Laporan Praktikum Pemrograman Lanjut Bab 4 Fakultas Ilmu Komputer Universitas Brawijaya 2016/2017
Soal :
Source code :
Class ATM1
Class ATM2
Download the file here
Soal :
Anda saat ini bekerja sebagai IT engineer di bank XY, dan
anda diminta untuk membuat
sistem
transaksi yang ada di mesin ATM yang baru dibeli. Aplikasi yang anda buat harus memenuhi requirement yang telah
dirancang oleh analis di bank XY. Kira-kira begini requirementnya:
- Informasi rekening (saldo, nomor rekening, nama
pemegang rekening) tidak bisa diubah
ubah
oleh nasabah secara langsung.
- Nomer rekening terdiri dari 15 digit, yang mana 3 digit
awal menentukan jenis rekening
yang
dimiliki oleh nasabah:
- 001 : rekening gold, memiliki limit penarikan tunai 10
juta, tanpa biaya transfer
- 192 : rekening silver, memiliki limit penarikan tunai 7
juta, namun ketika
transfer akan
dikenakan
biaya admin 6500
- 283 : rekening bronze, memiliki limit penarikan tunai 5
juta, namun ketika
transfer akan dikenakan biaya admin 7500
- Nasabah harus memiliki saldo minimal 10000, jika saldo
pasca transaksi kurang dari batas
minimal
tadi, maka transaksi dianggap gagal
- Buatlah sistem ATM tadi terbatas pada penarikan tunai
dan transfer saja, dan sebelum
memulai
transaksi harus melakukan otentikasi dahulu dengan memasukkan PIN dan nomor rekening.
Class ATM1
package bab4enkapsulasi; public class ATM1 { protected int accountno, accounttf; private long balance, wdraw, limit, tip, trf; private boolean acc = false, chk = false; private final String customer[][] = { {"Sarah", "001926710563936", "5743", "50000000", "0"}, {"Luna", "283082165779265", "3003", "6000000", "0"}, {"Shabria", "192551782902316", "0115", "10000000", "0"}, {"Nina", "192662893540164", "6321", "7005000", "0"}, {"Ellise", "001856782001327", "7654", "9000000", "0"}}; public void category(String s, int z) { acc = false; for (int i = 0; i < customer.length; i++) { if ((customer[i][1].equalsIgnoreCase(s)) && (Integer.parseInt(customer[i][2]) == z)) { accountno = i; if (Integer.parseInt(customer[i][1].substring(0, 3)) == 001) { tip = 0; limit = 10000000; } if (Integer.parseInt(customer[i][1].substring(0, 3)) == 192) { tip = 6500; limit = 7000000; } if (Integer.parseInt(customer[i][1].substring(0, 3)) == 283) { tip = 7500; limit = 5000000; } acc = true; System.out.println("WELCOME TO THP BANK"); showAcc(i); } } if (!acc) { System.out.println("YOU'RE ENTERING WRONG DATA"); } } public void check(String s) { for (int i = 0; i < customer.length; i++) { if (customer[i][1].equalsIgnoreCase(s)) { accounttf = i; chk = true; } } } public boolean getCheck() { return acc; } public void showAcc(int b) { System.out.println("Name : " + customer[b][0] + "\nAccount Number : " + customer[b][1] + "\nBalance :" + customer[b][3]); } public void wd(long c) { wdraw += c; balance = Integer.parseInt(customer[accountno][3]); if ((wdraw < limit) && ((balance - c) >= 10000)) { balance -= c; customer[accountno][3] = String.valueOf(balance); } else { System.out.println("TRANSACTION IS CANCELED"); wdraw -= c; } this.showAcc(accountno); } public void tfr(long c) { wdraw += c; balance = Integer.parseInt(customer[accountno][3]); trf = Integer.parseInt(customer[accounttf][3]); if ((wdraw < limit) && ((balance - c) >= 10000)) { balance -= (c + tip); trf = +c; customer[accountno][3] = String.valueOf(balance); customer[accounttf][3] = String.valueOf(trf); System.out.println("YOU'RE TRANSFERRING FROM ACCOUNT : "); showAcc(accountno); System.out.println("TRANSFER TO ACCOUNT : "); showAcc(accounttf); System.out.println("TRANSACTION SUCCESSFUL"); } else { wdraw -= c; System.out.println("TRANSACTION FAILED"); } } }
Class ATM2
package bab4enkapsulasi; import java.util.Scanner; public class ATM2 { public static void main(String[] args) { Scanner sausan = new Scanner(System.in); ATM1 sarah = new ATM1(); String accno; char end = 'n'; int choose, pin; do { System.out.println("WELCOME TO THP BANK"); System.out.println("Enter your account number : "); accno = sausan.next(); System.out.println("Enter your PIN : "); pin = sausan.nextInt(); sarah.category(accno, pin); if (sarah.getCheck()) { System.out.println("1. Withdrawal\n2. Transfer\nChoose : "); choose = sausan.nextInt(); if (choose == 1) { System.out.println("Withdraw Rp "); sarah.wd(sausan.nextLong()); } if (choose == 2) { System.out.println("Transfer to "); sarah.check(sausan.next()); System.out.println("How many?"); sarah.tfr(sausan.nextLong()); } System.out.println("TRANSACTION SUCCESSFUL. CONTINUE TRANSACTION?"); end = sausan.next().charAt(0); } } while (end == 'y'); } }
Download the file here
0 comments:
Posting Komentar