1.Penjelasan.
Class Toll Machine:Tempat pengaturan utama
Keypad:Inpud(Scanner ID pada kartu ATM)
Screen:Penampilan Pesan
Account dan database:Account merupakan isi dari data kartu tersebut dan database adalah penyimpan data dari kartu tersebut. Kedua class ini berhubungan.
Nota; Nota hasil akhir(Berupa kertas)
Gate: Mengatur apakah mobil boleh lewat atau tidak.
Main:Program Utama

2.Screen menampilkan hasil transaksi dan mengeluarkan nota.



3.Source Code

Class
Toll Machine
  1. public class TollMachine
  2. {
  3.     private int cost;
  4.     private Account_Database acc_db;
  5.     private Keypad keypad;
  6.     private Nota nota;
  7.     private Screen screen;
  8.     private Gate gate;
  9.     public TollMachine()
  10.     {
  11.         cost = 10000;
  12.         acc_db = new Account_Database();
  13.         keypad = new Keypad();
  14.         screen = new Screen();
  15.         gate = new Gate();
  16.     }
  17.     public void run()
  18.     {
  19.         while(true)
  20.         {
  21.             gate.closeGate();
  22.             screen.displayMessageLine("Please enter your Card Number\n");
  23.             int accNum = keypad.getInput();
  24.             if(acc_db.authenticateUser(accNum))
  25.             {
  26.                 if(acc_db.getAccountBalance(acc_db.getAccount(accNum)) >= cost)
  27.                 {
  28.                     acc_db.tollpay(acc_db.getAccount(accNum), cost);
  29.                     nota = new Nota(acc_db.getAccount(accNum).getBalance(), cost);
  30.                     nota.print();
  31.                     screen.displayMessageLine("Thank you for using our service\nPlease take your card and proof of transaction\n");
  32.                     gate.openGate();
  33.                 }
  34.                 else
  35.                 {
  36.                     screen.displayMessageLine("Insufficient funds\nPlease take your card back\n");
  37.                 }
  38.             }
  39.             else
  40.             {
  41.                 screen.displayMessageLine("Card Number not found\nPlease take your card back");
  42.             }
  43.         }
  44.     }
  45. }
Keypad
  1. import java.util.Scanner;
  2. public class Keypad
  3. {
  4.     private Scanner input;
  5.     public Keypad()
  6.     {  
  7.        input = new Scanner(System.in);  
  8.     }
  9.     public int getInput()
  10.     {  
  11.        return input.nextInt();  
  12.     }
  13. }

Screen
  1. public class Screen
  2. {
  3.     public void displayMessageLine(String message)
  4.     {  
  5.        System.out.println(message);  
  6.     }
  7. }

Database
  1. public class Account_Database
  2. {
  3.     // instance variables - replace the example below with your own
  4.     private Account accounts[];
  5.     public Account_Database()
  6.     {
  7.         accounts = new Account[6];
  8.         accounts[0] = new Account(13579,1000000);
  9.         accounts[1] = new Account(24680, 400000);
  10.         accounts[2] = new Account(16124, 100000);
  11.         accounts[3] = new Account(16001, 50000);
  12.         accounts[4] = new Account(16002, 10000);
  13.         accounts[5] = new Account(10001, 9999);
  14.     }
  15.     public Account getAccount(int AccountNumber)
  16.     {
  17.         for(Account currentAccount : accounts)
  18.         {
  19.             if ( currentAccount.getAccountNumber() == AccountNumber ) return currentAccount;
  20.         }
  21.         return null;
  22.     }
  23.     public boolean authenticateUser(int UserAccount)
  24.     {
  25.         Account userAccount = getAccount(UserAccount);
  26.         if(userAccount == null)
  27.         return false;
  28.         return true;
  29.     }
  30.     public int getAccountBalance(Account useraccount)
  31.     {
  32.         return useraccount.getBalance();
  33.     }
  34.     public void tollpay(Account useraccount, int amount)
  35.     {
  36.         useraccount.pay(amount);
  37.     }
  38. }
Account
  1. public class Account
  2. {
  3.     private int accountNumber;
  4.     private int balance;
  5.     public Account(int AccountNumber, int Balance)
  6.     {
  7.         accountNumber = AccountNumber;
  8.         balance = Balance;
  9.     }
  10.    
  11.     public int getBalance()
  12.     {
  13.         return balance;
  14.     }
  15.     public int getAccountNumber()
  16.     {
  17.         return accountNumber;
  18.     }
  19.     public void pay(int Cost)
  20.     {
  21.         balance = balance - Cost;
  22.     }
  23. }


Nota
  1. import java.util.Date;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. public class Nota
  5. {
  6.     int balance;
  7.     int price;
  8.     private Date date;
  9.     private DateFormat dateFormat;
  10.     public Nota(int Balance, int Price)
  11.     {
  12.         balance = Balance;
  13.         price = Price;
  14.         dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  15.         date = new Date();
  16.     }
  17.     public void print()
  18.     {
  19.         System.out.println("###############################################");
  20.         System.out.println("##Perusahaan A Toll Gate");
  21.         System.out.println("##Tanggal Transaksi: " + dateFormat.format(date));
  22.         System.out.println("##Biaya Tol: " + price);
  23.         System.out.println("##Sisa Saldo: " + balance);
  24.         System.out.println("###############################################");
  25.        
  26.     }
  27. }


Gate
  1. public class Gate
  2. {
  3.     boolean open;
  4.     public Gate()
  5.     {
  6.         open = false;
  7.     }
  8.     public void openGate()
  9.     {
  10.         open = true;
  11.     }
  12.     public void closeGate()
  13.     {
  14.         open = false;
  15.     }
  16. }

Main

  1. public class Main
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         TollMachine mesinToll = new TollMachine();
  6.         mesinToll.run();
  7.     }
  8. }


4.
TollMachine tollMach1 = new TollMachine();
tollMach1.run();
Please enter your Card Number

12345
Card Number not found
Please take your card back
Please enter your Card Number

13579
###############################################
##Perusahaan A Toll Gate
##Tanggal Transaksi: 2017/10/27 10:49:41
##Biaya Tol: 10000
##Sisa Saldo: 990000
###############################################
Thank you for using our service
Please take your card and proof of transaction

Please enter your Card Number

16002
###############################################
##Perusahaan A Toll Gate
##Tanggal Transaksi: 2017/10/27 10:49:47
##Biaya Tol: 10000
##Sisa Saldo: 0
###############################################
Thank you for using our service
Please take your card and proof of transaction

Please enter your Card Number

16002
Insufficient funds
Please take your card back

Please enter your Card Number

    VM terminated.
TollMachine tollMach1 = new TollMachine();
tollMach1.run();
Please enter your Card Number



















Komentar

Postingan populer dari blog ini

ATM study case.

Tugas Rk2 Elicitation