public class ATM {
String nasabah; double saldo; int
nTransaksi=0;
Histori[] histori = new Histori[10];
public ATM(){}
public ATM(String nasabah, double saldo){
this.nasabah=nasabah;
this.saldo=saldo }
void menuUtama(){
System.out.println("ATM\n\n");
System.out.println("1. Tarik
tunai");
System.out.println("2. Setor
tunai");
System.out.println("3. Info
Saldo");
System.out.println("4. Histori
transaksi");
System.out.println("0. Keluar\n");
System.out.print("Masukkan pilihan
:"); }
void menuTarik(){
System.out.println("ATM\n\n");
System.out.println("1. Tarik
tunai\n");
System.out.println("saldo anda
:"+this.saldo+"\n");
System.out.print("Masukkan nominal
:");}
void tarikTunai(double nominal){
if (this.saldo>=nominal){
histori[nTransaksi] = new
Histori();
histori[nTransaksi].jnsTransaksi =
"tarikTunai";
histori[nTransaksi].saldoAwal =
this.saldo;
histori[nTransaksi].saldoAhir =
this.saldo-=nominal;
nTransaksi++;
} else {
System.out.println("Saldo anda tidak
mencukupi");}
}
void menuSetor(){
System.out.println("ATM\n\n");
System.out.println("2. Setor
tunai\n");
System.out.println("saldo anda
:"+this.saldo+"\n");
System.out.print("Masukkan nominal
:");}
void setorTunai(double nominal){
histori[nTransaksi] = new Histori();
histori[nTransaksi].jnsTransaksi =
"setorTunai";
histori[nTransaksi].saldoAwal =
this.saldo;
histori[nTransaksi].saldoAhir =
this.saldo+=nominal;
nTransaksi++; }
void ceksaldo(){
System.out.println("Saldo Anda :
"+this.saldo); }
void menuHistori(){
System.out.println("ATM\n\n");
System.out.println("4. Histori
Transaksi\n");
System.out.println("No.\tJenis
Transaksi\t\t nominal \t\tSaldo Awal\t\tSaldo Ahir");
for(int n=0;n<this.nTransaksi;n++) {
System.out.println(n+".\t"+histori[n].jnsTransaksi+"\t\t"+histori[n].saldoAwal+"\t\t"+histori[n].saldoAhir);
}
}
}
*untuk class yang kedua menjalankan program atm*
public class ATMberaksi {
public static void main(String[] args) {
Scanner inputan = new
Scanner(System.in);
ATM atm = new
ATM("Fajar",9000);
int pil=0; double nominal;
do {
atm.menuUtama();
pil=inputan.nextInt();
switch (pil) {
case 1:
atm.menuTarik();
nominal=inputan.nextDouble();
atm.tarikTunai(nominal);
break;
case 2:
atm.menuSetor();
nominal=inputan.nextDouble();
atm.setorTunai(nominal);
break;
case 3:
atm.ceksaldo();
break;
case 4:
atm.menuHistori();
break;
}
} while(pil!=0);
}
}
*untuk class yang terakhr tentang histori / transaksi atm *
public class Histori {
String jnsTransaksi;
double saldoAwal, saldoAhir;
public Histori(){
}
}
* semoga bermanfaat bagi kalian*
0 komentar:
Posting Komentar