Kali ini aku mau nge post lagi nih tentang java, kali ini membuat program membuat judul yang di atas...
SELAMAT MENCOBA :D
____________________________________________________________________________
Pertama buatlah java class dan beri nama terserah kamu, tapi kalo kepunyakan aku ku beri nama "InputArray2"... Codingannya di bawah ini...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package JavaApplication6;
import javax.swing.JOptionPane;
/**
*
* @author defryan24
*/
public class InputArray2 {
static int total=0;
static int max_user = 3; //setting jumlah maximal user
public static String up_nama[]=new String[max_user];
public static String up_pass[]=new String[max_user];
public static String up_gender[]=new String[max_user];
public static String up_sapaan[]=new String[max_user];
public static String nama;
public static String sapaan;
public static void daftar(){
if(total>=up_nama.length){
String[] pilihan = {"Sign In"};
int respons = JOptionPane.showOptionDialog(null
,"Maaf pendaftaran penuh\nSilakan anda :"
,"Pendaftaran Penuh!"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,pilihan
,null
);
if(respons==0){
masuk();
}
}
else{
inputnama();
inputJK();
inputpass();
total++;
}
menu_utama();
}
public static void masuk(){
String in_user;
String cek_in_user = null;
String cek_in_pass;
int j;
int posisi;
if(total==0){
String[] pilihan = {"Sign UP"};
int respons = JOptionPane.showOptionDialog(null
,"Maaf Belum ada user yang terdaftar,\n anda harus SIGN UP dahulu :"
,"USER KOSONG !"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,pilihan
,null
);
if(respons==0){
daftar();
}
}
else{
in_user = login_nama();
for(j=0;j<up_nama.length;j++){
if(up_nama[j]==null){
up_nama[j]="";
}
cek_in_user=up_nama[j];
if(cek_in_user.equals(in_user)){
posisi=j;
nama = in_user;
cek_pass(posisi);
break;
}
else if(j==up_nama.length-1){
String[] pilihan = {"Sign Up","Sign In"};
int respons = JOptionPane.showOptionDialog(null
,"Maaf "+nama+" belum terdaftar, silakan Sign Up atau Sign In dengan user lain:"
,"Belum terdaftar !"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,pilihan
,null
);
if(respons==0){
daftar();
}
else if(respons == 1){
login_nama();
}
}
}
}
}
public static void cek_pass(int posisi){
String in_pass;
in_pass=login_pass();
if(up_pass[posisi].equals(in_pass)){
sapaan=up_sapaan[posisi];
JOptionPane.showMessageDialog(null, "SELAMAT DATANG "+sapaan+" "+nama,"WELCOME",JOptionPane.INFORMATION_MESSAGE);
Konverter.menu_1();
}
else{
cek_pass(posisi);
}
}
public static void konfirm_exit(String menu) {
int konfirmasi ;
konfirmasi = JOptionPane.showConfirmDialog(null, "Anda yakin mau keluar ?","Exit Confirmation", JOptionPane.YES_NO_OPTION);
switch(konfirmasi){
case -1:
case 0 : System.exit(0);
break;
case 1 :
if("menu_1".equals(menu)){
menu_utama();
}
break;
}
}
public static void menu_utama(){
String option[]={"Sign UP","Sign IN","EXIT"};
int respons = JOptionPane.showOptionDialog(null,
"SILAKAN PILIH MENU :",
"MAIN MENU",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null ,
option ,
null);
switch(respons){
case 0:daftar();
break;
case 1:masuk();
break;
case 2:
case -1:
konfirm_exit("menu_1");
}
}
public static void main (String[] args){
menu_utama();
}
public static String login_nama() {
String input = JOptionPane.showInputDialog(null, "Inputkan nama anda \n(hanya huruf & _)", "Sign In", JOptionPane.INFORMATION_MESSAGE);
try{
if(input.isEmpty()||input.equals(" ")){
JOptionPane.showMessageDialog(null,"Nama tidak boleh kosong","Error!", JOptionPane.ERROR_MESSAGE);
login_nama();
}
else if(!input.matches("([a-zA-Z_]{1,})")){
JOptionPane.showMessageDialog(null,"Tidak boleh didahului angka","Notice!", JOptionPane.INFORMATION_MESSAGE);
login_nama();
}
}
catch(NullPointerException f){
JOptionPane.showMessageDialog(null,"Jangan di Cancel","Error!", JOptionPane.ERROR_MESSAGE);
login_nama();
}
return input;
}
private static String login_pass() {
String input = JOptionPane.showInputDialog(null, "Inputkan password", "Sign In", JOptionPane.INFORMATION_MESSAGE);
try{
if(input.isEmpty()||input.equals(" ")){
JOptionPane.showMessageDialog(null,"Password tidak boleh kosong","Error!", JOptionPane.ERROR_MESSAGE);
login_pass();
}
}
catch(NullPointerException f){
JOptionPane.showMessageDialog(null,"Jangan di Cancel","Error!", JOptionPane.ERROR_MESSAGE);
login_pass();
}
return input;
}
public static void inputnama() {
String input = JOptionPane.showInputDialog(null, "Inputkan nama anda (hanya huruf & _)", "SIGN UP", JOptionPane.PLAIN_MESSAGE);
try{
if(input.isEmpty()||input.equals(" ")){
JOptionPane.showMessageDialog(null,"Nama tidak boleh kosong","Error!", JOptionPane.ERROR_MESSAGE);
inputnama();
}
else if(!input.matches("([a-zA-Z_]{1,})")){
JOptionPane.showMessageDialog(null,"Tidak boleh didahului angka","Notice!", JOptionPane.INFORMATION_MESSAGE);
inputnama();
}
else{
up_nama[total]=input;
}
}
catch(NullPointerException f){
JOptionPane.showMessageDialog(null,"Jangan di Cancel","Error!", JOptionPane.ERROR_MESSAGE);
inputnama();
}
}
private static void inputpass() {
String input = JOptionPane.showInputDialog(null, "Inputkan password", "SIGN UP Input password!", JOptionPane.PLAIN_MESSAGE);
try{
if(input.isEmpty()||input.equals(" ")){
JOptionPane.showMessageDialog(null,"Password tidak boleh kosong","Error!", JOptionPane.ERROR_MESSAGE);
inputpass();
}
else{
up_pass[total]=input;
}
}
catch(NullPointerException f){
JOptionPane.showMessageDialog(null,"Jangan di Cancel","Error!", JOptionPane.ERROR_MESSAGE);
inputpass();
}
}
private static void inputJK() {
String[] pilihan = {"Laki-laki","Perempuan"};
int respons = JOptionPane.showOptionDialog(null
,"Jenis Kelamin anda?"
,"Pilih Jenis Kelamin"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,pilihan
,null
);
switch(respons){
case 0 : up_gender[total]="Laki-laki";
up_sapaan[total]="BRO";
break;
case 1 : up_gender[total]="Perempuan";
up_sapaan[total]="SIS";
break;
case -1:
JOptionPane.showMessageDialog(null, "Pilih jenis kelamin dulu","Jenis Kelamin!",JOptionPane.ERROR_MESSAGE);
inputJK();
break;
}
}
}
____________________________________________________________________________
Sek, sek, sek, belum selesai sampai di sini kawan...
Buat satu java class lagi bernamakan terserah kamu kalo punyaku ku beri nama "Konverter", la file konverter ini nantinya yang akan di panggil melalui file "inputarray2" di atas. Berikut ini coding dari file konverter...
____________________________________________________________________________
package JavaApplication6;
import javax.swing.JOptionPane;
/**
*
* @author defryan24
*/
public class Konverter {
private static String nama=InputArray2.nama;
private static String sapaan=InputArray2.sapaan;
private static String age;
private static String jenis_kl;
public static int gender;
private static int des;
private static int validDes;
private static StringBuilder hasil;
public static void main(String ftm[]){
menu_1();
}
public static void menu_1() {
int konv_bilang;
String options[] = {"Konversi Bilangan","Membilang & Pecahan","Sign Out!"};
konv_bilang = JOptionPane.showOptionDialog(null,
"Selamat datang "+sapaan+" "+nama+"!!!\nPilih menu berikut",
"Main Menu", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, options, null);
switch(konv_bilang){
case 0 : menu_konversi();
break;
case 1 : menu_bilangan();
break;
case 2 :InputArray2.menu_utama();
break;
case -1 : konfirm_exit("menu_1");
break;
}
}
public static void konfirm_exit(String menu) {
int konfirmasi ;
konfirmasi = JOptionPane.showConfirmDialog(null, sapaan+" "+nama+", Anda yakin mau keluar ?","Exit Confirmation", JOptionPane.YES_NO_OPTION);
switch(konfirmasi){
case -1:
case 0 : System.exit(0);
break;
case 1 :
if("menu_1".equals(menu)){
menu_1();
}
else if("menu_konversi".equals(menu)){
menu_konversi();
}
else if("menu_bilangan".equals(menu)){
menu_bilangan();
}
break;
}
}
public static void menu_konversi() {
String option[] = {"BINER","HEXA","OKTAL","<<BACK>>","CLOSE>>"};
int respons = JOptionPane.showOptionDialog(null
,"Konversi dari Desimal ke ?"
,"Pilih Konversi"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,option
,null
);
switch(respons){
case 0 : konv("Biner");
break;
case 1 : konv("Heksa");
break;
case 2 : konv("Oktal");
break;
case 3 : menu_1();
break;
case 4 :
case -1 : konfirm_exit("menu_konversi");
break;
}
}
private static void tampilkonv(int des, String ke) {
hasil= new StringBuilder();
if(ke.equals("Biner")){
Biner(des);
}
else if(ke.equals("Oktal")){
Oktal(des);
}
else if(ke.equals("Heksa")){
Heksa(des);
}
System.out.println("\n\nBilangan desimal : "+des+" "+ke+"nya Adalah: "+hasil);
JOptionPane.showMessageDialog(null, "Bilangan desimal : "+des+" "+ke+"nya Adalah: "+hasil, "HASIL KONVERSI", JOptionPane.PLAIN_MESSAGE);
menu_konversi();
}
private static void InpBil(String fungsi) {
String apa = null;
if("Biner".equals(fungsi)||"Heksa".equals(fungsi)||"Oktal".equals(fungsi)){
apa = "dikonversikan ke "+fungsi;
}
else if("bilang".equals(fungsi)){
apa = "di"+fungsi+"kan/dibaca (maksimal satu milyard)";
}
else if("desimal".equals(fungsi)||"rupiah".equals(fungsi)){
apa = "dipecah dalam "+fungsi+" (maksimal satu milyard)";
}
String bildes = JOptionPane.showInputDialog(null, "Inputkan bilangan desimal \n untuk "+apa, "Input desimal", JOptionPane.INFORMATION_MESSAGE);
try{
validDes=Integer.parseInt(bildes);
if(validDes>1000000000){
JOptionPane.showMessageDialog(null, "Nilai terlalu besar, maksimal satu milyard !", "Error!", JOptionPane.ERROR_MESSAGE);
InpBil(fungsi);
}
}
catch(NumberFormatException ft){
JOptionPane.showMessageDialog(null, "Inputkan angka !", "Error!", JOptionPane.ERROR_MESSAGE);
InpBil(fungsi);
}
}
private static void konv(String konv) {
if(konv.equals("Biner")){
InpBil("Biner");
des = validDes;
tampilkonv(des,"Biner");
}
else if (konv.equals("Heksa")){
InpBil("Heksa");
des = validDes;
tampilkonv(des,"Heksa");
}
else if (konv.equals("Oktal")){
InpBil("Oktal");
des = validDes;
tampilkonv(des,"Oktal");
}
}
private static void Biner(int n) {
String biner = null;
if(n>1){
Biner(n/2);
}
hasil.append(n%2);
}
private static void Heksa(int n) {
char [] daftarHexa={'0','1','2','3','4','5','6','7','8','9','A','B','C',
'D','E','F'};
if (n>1){
Heksa (n/16);
}
hasil.append(daftarHexa[n%16]);
}
private static void Oktal(int n) {
if(n>1){
Oktal(n/8);
}
hasil.append(n%8);
}
private static void menu_bilangan() {
String option[] = {"TERBILANG","PECAHAN RUPIAH","PECAHAN DESIMAL","<<BACK>>","CLOSE>>"};
int respons = JOptionPane.showOptionDialog(null
,"Pilih :"
,"Pilih Menu Membilang atau Pecahan"
,JOptionPane.YES_NO_CANCEL_OPTION
,JOptionPane.QUESTION_MESSAGE
,null
,option
,null
);
switch(respons){
case 0 : bil_pec("bilang");
break;
case 1 : bil_pec("rupiah");
break;
case 2 : bil_pec("desimal");
break;
case 3 : menu_1();
break;
case 4 :
case -1 : konfirm_exit("menu_bilangan");
break;
}
}
private static void bil_pec(String bilang) {
if(bilang.equals("bilang")){
InpBil("bilang");
des = validDes;
tampilbil(des,"bilang");
}
else if(bilang.equals("rupiah")){
InpBil("rupiah");
des = validDes;
tampilbil(des,"rupiah");
}
else if(bilang.equals("desimal")){
InpBil("desimal");
des = validDes;
tampilbil(des,"desimal");
}
}
private static void tampilbil(int des, String bilang) {
hasil= new StringBuilder();
String apase = "Bilangan";
String diapakan = " dipecah menjadi";
String petik=" ";
String apa="Pecahan";
if(bilang.equals("bilang")){
Bilang(des);
diapakan = " dibaca";
petik="'";
apa = "Terbilang";
}
else if(bilang.equals("rupiah")){
Pecah_rupiah(des);
apase="Uang Rp.";
apa+=" rupiah";
}
else if(bilang.equals("desimal")){
Pecah_desimal(des);
apa+=" desimal";
}
System.out.println("\n"+apase+" "+des+diapakan+" : \n\n"+petik+hasil+petik);
JOptionPane.showMessageDialog(null,apase+" "+des+diapakan+" : \n"+petik+hasil+petik,"Hasil "+apa,JOptionPane.INFORMATION_MESSAGE);
menu_bilangan();
}
public static void Bilang(int des) {
int f = 0;
String angka[] = {""," Se"," Dua "," Tiga "," Empat "," Lima "," Enam "," Tujuh "," Delapan "," Sembilan "};
String angka_2[] = {""," Satu "," Dua "," Tiga "," Empat "," Lima "," Enam "," Tujuh "," Delapan "," Sembilan "};
//String satuan[] = {""," puluh "," belas "," ratus "," ribu "," belas ribu "};
if(des>=1000000000){
hasil.append(angka_2[des/1000000000]);
hasil.append("milyar ");
des%=1000000000;
}
if(des>=100000000){
hasil.append(angka[des/100000000]);
if(des%100000000>1000000){
hasil.append("ratus ");
}
else{
hasil.append("ratus juta ");
}
des%=100000000;
}
if(des>=10000000){
int bantuan=des/1000000;
if(bantuan<20&&bantuan>10){
hasil.append(angka[bantuan%=10]);
hasil.append("belas juta ");
des=(des%10000000)-(bantuan%=10)*1000000;
}
else{
hasil.append(angka[des/10000000]);
if(des%10000000>=1000000){
hasil.append("puluh ");
}
else{
hasil.append("puluh juta ");
}
des%=10000000;
}
}
if(des>=1000000){
hasil.append(angka_2[des/1000000]);
hasil.append("juta ");
des%=1000000;
}
if(des>=100000){
hasil.append(angka[des/100000]);
if(des%100000>1000){
hasil.append("ratus ");
}
else{
hasil.append("ratus ribu ");
}
des%=100000;
}
if(des>=10000){
f++;
int bantuan=des/1000;
if(bantuan<20&&bantuan>10){
hasil.append(angka[bantuan%=10]);
hasil.append("belas ribu ");
des=(des%10000)-(bantuan%=10)*1000;
}
else{
hasil.append(angka[des/10000]);
if(des%10000>=1000){
hasil.append("puluh ");
}
else{
hasil.append("puluh ribu ");
}
des%=10000;
}
}
if(des>=1000){
if(f==1){
hasil.append(angka_2[des/1000]);
}
else{
hasil.append(angka[des/1000]);
}
hasil.append("ribu ");
des%=1000;
}
if(des>=100){
hasil.append(angka[des/100]);
hasil.append("ratus ");
des%=100;
}
if(des>=10){
if(des<20&&des>10){
hasil.append(angka[des%=10]);
hasil.append("belas ");
des=0;
}
else{
hasil.append(angka[des/10]);
hasil.append("puluh ");
des%=10;
}
}
hasil.append(angka_2[des]);
}
public static void Pecah_rupiah(int des) {
int A,B,C,D,E,F,G,H,I,J,K ;
A=des/100000;
des%=100000;
B=des/50000;
des%=50000;
C=des/20000;
des%=20000;
D=des/10000;
des%=10000;
E=des/5000;
des%=5000;
F=des/2000;
des%=2000;
G=des/1000;
des%=1000;
H=des/500;
des%=500;
I=des/100;
des%=100;
J=des/50;
des%=50;
K=des;
hasil.append(
"Banyaknya seratus ribuan = "+A
+"\n Banyaknya lima puluh ribuan = "+B
+"\n Banyaknya dua puluh ribuan = "+C
+"\n Banyaknya sepuluh ribuan = "+D
+"\n Banyaknya lima ribuan = "+E
+"\n Banyaknya dua ribuan = "+F
+"\n Banyaknya seribuan = "+G
+"\n Banyaknya lima ratusan = "+H
+"\n Banyaknya seratusan = "+I
+"\n Banyaknya lima puluhan = "+J
+"\n sisa = "+K
+"\n\n *) pecahan menurut pecahan rupiah\n Digunakan pecahan terbesar dahulu");
}
public static void Pecah_desimal(int des) {
int A,B,C,D,E,F,G,H,I,J,K,L,M ;
A=des/1000000000;
des%=1000000000;
B=des/100000000;
des%=100000000;
C=des/10000000;
des%=10000000;
D=des/1000000;
des%=1000000;
E=des/100000;
des%=100000;
F=des/10000;
des%=10000;
G=des/1000;
des%=1000;
H=des/100;
des%=100;
I=des/10;
des%=10;
J=des;
hasil.append(
"Nilai milyaran = "+A
+"\n Nilai ratusan juta = "+B
+"\n Nilai puluhan juta = "+C
+"\n Nilai jutaan = "+D
+"\n Nilai ratusan ribu = "+E
+"\n Nilai puluhan ribu = "+F
+"\n Nilai ribuan = "+G
+"\n Nilai ratusan = "+H
+"\n Nilai puluhan = "+I
+"\n Nilai satuan = "+J
+"\n\n *) pecahan menurut bilangan desimal");
}
}