Kamis, 01 Juni 2017

Hospital Queue Machine

Rumah sakit adalah institusi pelayanan kesehatan yang menyelenggarakan pelayanan kesehatan perorangan secara paripurna yang menyediakan pelayanan rawat inap, rawat jalan, dan gawat darurat.

Mesin antrian rumah sakit adalah mesin yang digunakan untuk mengelola nomor urut antrian pelanggan ataupun pasien. Mesin ini mempunyai fungsi untuk mempermudah dokter poli dan dokter umum, atau layanan lain pada rumah sakit tersebut, memanggil pelanggan, dan melayani sesuai dengan keperluan pelanggan pada masing-masing layanan.


Source code date:
/**
 * Write a description of class date here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
import java.util.*;
import java.text.*;
public class date
{
   public String getTanggal(){
       Date dNow = new Date();
       SimpleDateFormat ft = new SimpleDateFormat("E, dd.MM.yyyy   hh:mm:ss a");
       return ft.format(dNow);
   }
}

Source code Poli:
/**
 * Write a description of class Poli here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.util.*;
import java.text.*;
import javax.swing.*;
public class Poli
{
   private int nomorTA=0;
   private int nomorTM=0;
   private int nomorTD=0;
   private int nomorTG=0;
   private int nomorTK=0;
   private int antriTA=0;
   private int antriTM=0;
   private int antriTD=0;
   private int antriTG=0;
   private int antriTK=0;
   private date q;
   
   public void ticketT(char x){
       this.q = new date();
       if(x=='a'){
           String message1 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nPOLI ANAK\nA%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorTA+1, nomorTA-antriTA);
           JOptionPane.showMessageDialog(null, message1);
           nomorTA++;
       }
       else if(x=='b'){
           String message2 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nPOLI MATA\nB%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorTM+1, nomorTM-antriTM);
           JOptionPane.showMessageDialog(null, message2);
           nomorTM++;
       }
       else if(x=='c'){
           String message3 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nPOLI PENYAKIT DALAM\nC%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorTD+1, nomorTD-antriTD);
           JOptionPane.showMessageDialog(null, message3);
           nomorTD++;
       }
       else if(x=='d'){
           String message4 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nPOLI GIGI\nD%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorTG+1, nomorTG-antriTG);
           JOptionPane.showMessageDialog(null, message4);
           nomorTG++;
       }
       else if(x=='e'){
           String message5 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nPOLI KULIT\nE%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorTK+1, nomorTK-antriTK);
           JOptionPane.showMessageDialog(null, message5);
           nomorTK++;
       }
   }
   public void screenT(char y){
       if(y=='a'){
           antriTA++;
           String message6 = String.format("Pelayanan:\nPOLI ANAK\nA%d\n\nBelum mendapatkan pelayanan %d", nomorTA-(nomorTA-antriTA),nomorTA-antriTA);
           JOptionPane.showMessageDialog(null, message6);
       }
       else if(y=='b'){
           antriTM++;
           String message7 = String.format("Pelayanan:\nPOLI MATA\nB%d\n\nBelum mendapatkan pelayanan %d", nomorTM-(nomorTM-antriTM),nomorTM-antriTM);
           JOptionPane.showMessageDialog(null, message7);
       }
       else if(y=='c'){
           antriTD++;
           String message8 = String.format("Pelayanan:\nPOLI PENYAKIT DALAM\nC%d\n\nBelum mendapatkan pelayanan %d", nomorTD-(nomorTD-antriTD),nomorTD-antriTD);
           JOptionPane.showMessageDialog(null, message8);
       }
       else if(y=='d'){
           antriTG++;
           String message9 = String.format("Pelayanan:\nPOLI GIGI\nD%d\n\nBelum mendapatkan pelayanan %d", nomorTG-(nomorTG-antriTG),nomorTG-antriTG);
           JOptionPane.showMessageDialog(null, message9);
       }
       else if(y=='e'){
           antriTK++;
           String message0 = String.format("Pelayanan:\nPOLI KULIT\nE%d\n\nBelum mendapatkan pelayanan %d", nomorTK-(nomorTK-antriTK),nomorTK-antriTK);
           JOptionPane.showMessageDialog(null, message0);
       }
   }
}

Source code Umum:
/**
 * Write a description of class Umum here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.util.*;
import java.text.*;
import javax.swing.*;
public class Umum
{
   private int nomorU=0;
   private int antriU=0;
   private date q;

   Date dNow = new Date();
   SimpleDateFormat ft = new SimpleDateFormat("E, dd.MM.yyyy   hh:mm:ss a");
   
   public void ticketU(){
       this.q = new date();
       String message1 = String.format("#######################################\nd Hospital\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nUMUM\nU%d\n\nTerima kasih telah tertib\nJumlah antrian: %d\n#######################################", nomorU+1, nomorU-antriU);
       JOptionPane.showMessageDialog(null, message1);
       nomorU++;
   }
   public void screenU(char x){
       antriU++;
       if(x=='a'){
           String message2 = String.format("Pelayanan:\nUMUM1\nU%d\n\nBelum mendapatkan pelayanan %d", nomorU-(nomorU-antriU),nomorU-antriU);
           JOptionPane.showMessageDialog(null, message2);
       }
       else if(x=='b'){
           String message2 = String.format("Pelayanan:\nUMUM2\nU%d\n\nBelum mendapatkan pelayanan %d", nomorU-(nomorU-antriU),nomorU-antriU);
           JOptionPane.showMessageDialog(null, message2);
       }
   }
}

Source code hospital:
/**
 * Write a description of class hospital here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class hospital
{
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private Poli a;
   private Umum b;
   public hospital(){
       prepareGUI();
       this.a = new Poli();
       this.b = new Umum();
   }
   public static void main(String[] args){
       hospital test = new hospital();
       test.showButton();
   }
   private void prepareGUI(){
       mainFrame = new JFrame("d Hospital");
       mainFrame.setSize(300,150);
       mainFrame.setLayout(new GridLayout(3, 1));
      
       mainFrame.addWindowListener(new WindowAdapter() {
           public void windowClosing(WindowEvent windowEvent){
               System.exit(0);
           }        
       });
       
       headerLabel = new JLabel("", JLabel.CENTER);        
       statusLabel = new JLabel("", JLabel.CENTER);    
       statusLabel.setSize(350,100);

       controlPanel = new JPanel();
       controlPanel.setLayout(new FlowLayout());

       mainFrame.add(headerLabel);
       mainFrame.add(controlPanel);
       mainFrame.add(statusLabel);
       mainFrame.setVisible(true);  
   }
   private void showButton(){
       headerLabel.setText("Selamat datang..");
       
       JButton nButton = new JButton("Pasien"); 
       JButton pButton = new JButton("Pegawai"); 
       nButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){       
               String pilihan = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Poli\n 2. Umum");
               char c = pilihan.charAt(0);
               if(c=='1'){
                   String pilih = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Poli Anak\n 2. Poli Mata\n 3. Poli Penyakit Dalam\n 4. Poli Gigi\n 5. Poli Kulit");
                   char x = pilih.charAt(0);
                   if(x=='1')
                       a.ticketT('a');
                   else if(x=='2')
                       a.ticketT('b');
                   else if(x=='3')
                       a.ticketT('c');
                   else if(x=='4')
                       a.ticketT('d');
                   else if(x=='5')
                       a.ticketT('e');
                   else{
                       String message1 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                       JOptionPane.showMessageDialog(null, message1);
                   }
               }
               else if(c=='2'){
                   b.ticketU();
               }
               else{
                   String message2 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                   JOptionPane.showMessageDialog(null, message2);
               }
           }          
       });
       pButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               String pil = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Poli\n 2. Umum");
               char c = pil.charAt(0);
               if(c=='1'){
                   String p = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Poli Anak\n 2. Poli Mata\n 3. Poli Penyakit Dalam\n 4. Poli Gigi\n 5. Poli Kulit");
                   char y = p.charAt(0);
                   if(y=='1')
                       a.screenT('a');
                   else if(y=='2')
                       a.screenT('b');
                   else if(y=='3')
                       a.screenT('c');
                   else if(y=='4')
                       a.screenT('d');
                   else if(y=='5')
                       a.screenT('e');
                   else{
                       String message3 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                       JOptionPane.showMessageDialog(null, message3);
                   }
               }
               else if(c=='2'){
                   String z = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Umum1\n 2. Umum2");
                   char w = z.charAt(0);
                   if(w=='1')
                       b.screenU('a');
                   if(w=='2')
                       b.screenU('b');
                   else{
                       String message4 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                       JOptionPane.showMessageDialog(null, message4);
                   }
               }
               else{
                   String message4 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                   JOptionPane.showMessageDialog(null, message4);
               }
           }          
       });
       controlPanel.add(nButton);
       controlPanel.add(pButton);
       mainFrame.setVisible(true);  
   }
}



Hasilnya:

Pilihan Pasien, untuk mencetak kartu antrian
Pilihan Pegawai, untuk tiap kali selesai melayani pelanggan.


Apabila dipilih pada Pasien, maka..


Untuk pilihan 1, yakni Poli


Untuk pilihan 1, yakni Poli Anak
pilihan 2, yakni Poli Mata
pilihan 3, yakni Poli Penyakit Dalam
dll.


dan seterusnya.

Sistem dari mesin antrian rumah sakit ini hampir sama dengan mesin antrian pada bank yang telah saya post sebelumnya. Bedanya dalam mesin antrian rumah sakit ini, saya tambahkan banyak pilihan lagi setelah masuk pada kotak dialog Poli pada pilihan Pasien, selain itu juga ada 2 dokter umum yang pemilihan pelayanannya diatur oleh pihak pegawai.

Senin, 08 Mei 2017

ATM Machine

Source code: ATM
/**
 * Write a description of class ATM here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
public class ATM
{
   private boolean userAuthenticated;
   private int currentAccountNumber;
   private Screen screen;
   private Keypad keypad;
   private CashDispenser cashDispenser;
   private DepositSlot depositSlot;
   private BankDatabase bankDatabase;
   
   private static final int BALANCE_INQUIRY = 1;
   private static final int WITHDRAWAL = 2;
   private static final int DEPOSIT = 3;
   private static final int EXIT = 4;
   
   public ATM(){
       userAuthenticated = false;
       currentAccountNumber = 0;
       screen = new Screen();
       keypad = new Keypad();
       cashDispenser = new CashDispenser();
       depositSlot = new DepositSlot();
       bankDatabase = new BankDatabase();
   }
   public void run(){
       while(true){
           while(!userAuthenticated){
               screen.displayMessageLine("\nWelcome!");
               authenticateUser();
           }
           performTransactions();
           userAuthenticated = false;
           currentAccountNumber = 0;
           screen.displayMessageLine("\nThank you! Goodbye!");
       }
   }
   private void authenticateUser(){
       screen.displayMessage("\nPlease enter your account number: ");
       int accountNumber = keypad.getInput();
       screen.displayMessage("\nEnter your PIN: ");
       int pin = keypad.getInput();
       
       userAuthenticated = bankDatabase.authenticateUser(accountNumber, pin);
       
       if(userAuthenticated){
           currentAccountNumber = accountNumber;
       }
       else
           screen.displayMessageLine("Invalid account number or PIN. Please try again.");
   }
   private void performTransactions(){
       Transaction currentTransaction = null;
       boolean userExited = false;
       while(!userExited){
           int mainMenuSelection = displayMainMenu();
           switch(mainMenuSelection){
               case BALANCE_INQUIRY:
               case WITHDRAWAL:
               case DEPOSIT:
                   currentTransaction = createTransaction(mainMenuSelection);
                   currentTransaction.execute();
                   break;
               case EXIT:
                   screen.displayMessageLine("\nExiting the system...");
                   userExited = true;
                   break;
               default:
                   screen.displayMessageLine("\nYou did not enter a valid selection. Try again.");
                   break;
           }
       }
   }
   private int displayMainMenu(){
       screen.displayMessageLine("\nMain menu:");
       screen.displayMessageLine("1 - View my balance");
       screen.displayMessageLine("2 - Withdraw cash");
       screen.displayMessageLine("3 - Deposit funds");
       screen.displayMessageLine("4 - Exit\n");
       screen.displayMessage("Enter a choice: ");
       return keypad.getInput();
   }
   private Transaction createTransaction( int type ){
       Transaction temp = null;
       switch(type){
           case BALANCE_INQUIRY:
               temp = new BalanceInquiry(currentAccountNumber, screen, bankDatabase);
               break;
           case WITHDRAWAL:
               temp = new Withdrawal(currentAccountNumber, screen, bankDatabase, keypad, cashDispenser);
               break;
           case DEPOSIT:
               temp = new Deposit(currentAccountNumber, screen, bankDatabase, keypad, depositSlot);
               break;
       }
       return temp;
   }
}

Source code: Screen
/**
 * Write a description of class Screen here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
public class Screen
{
   public void displayMessage(String message){
       System.out.print(message);
   }
   public void displayMessageLine(String message){
       System.out.println(message);
   }
   public void displayDollarAmount(double amount){
       System.out.printf("$%,.2f", amount);
   }
}

Source code: Keypad
/**
 * Write a description of class Keypad here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
import java.util.Scanner;
public class Keypad
{
   private Scanner input;
   public Keypad(){
       input = new Scanner(System.in);
   }
   public int getInput(){
       return input.nextInt();
   }
}

Source code: CashDispenser
/**
 * Write a description of class CashDispenser here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class CashDispenser
{
   private final static int INITIAL_COUNT = 500;
   private int count;
   public CashDispenser(){
       count = INITIAL_COUNT;
   }
   public void dispenseCash(int amount){
       int billsRequired = amount/20;
       count -= billsRequired;
   }
   public boolean isSufficientCashAvailable(int amount){
       int billsRequired = amount/20;
       if(count>=billsRequired)
           return true;
       else
           return false;
   }
}

Source code: DepositSlot
/**
 * Write a description of class DepositSlot here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class DepositSlot
{
   public boolean isEnvelopeReceived(){
       return true;
   }
}

Source code: Account
/**
 * Write a description of class Account here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class Account
{
   private int accountNumber;
   private int pin;
   private double availableBalance;
   private double totalBalance;
   public Account(int theAccountNumber, int thePIN, double theAvailableBalance, double theTotalBalance){
       accountNumber = theAccountNumber;
       pin = thePIN;
       availableBalance = theAvailableBalance;
       totalBalance = theTotalBalance;
   }
   public boolean validatePIN(int userPIN){
       if(userPIN==pin)
           return true;
       else
           return false;
   }
   public double getAvailableBalance(){
       return availableBalance;
   }
   public double getTotalBalance(){
       return totalBalance;
   }
   public void credit(double amount){
       totalBalance += amount;
   }
   public void debit(double amount){
       availableBalance -= amount;
       totalBalance -= amount;
   }
   public int getAccountNumber(){
       return accountNumber;
   }
}

Source code: BankDatabase
/**
 * Write a description of class BankDatabase here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class BankDatabase
{
   private Account[] accounts;
   public BankDatabase(){
       accounts = new Account[2];
       accounts[0] = new Account(12345, 54321, 1000.0, 1200.0);
       accounts[1] = new Account(98765, 56789, 200.0, 200.0);
   }
   private Account getAccount(int accountNumber){
       for(Account currentAccount:accounts){
           if(currentAccount.getAccountNumber()==accountNumber)
               return currentAccount;
       }
       return null;
   }
   public boolean authenticateUser(int userAccountNumber, int userPIN){
       Account userAccount = getAccount(userAccountNumber);
       if(userAccount != null)
           return userAccount.validatePIN(userPIN);
       else
           return false;
   }
   public double getAvailableBalance(int userAccountNumber){
       return getAccount(userAccountNumber).getAvailableBalance();
   }
   public double getTotalBalance(int userAccountNumber){
       return getAccount(userAccountNumber).getTotalBalance();
   }
   public void credit(int userAccountNumber, double amount){
       getAccount(userAccountNumber).credit(amount);
   }
   public void debit(int userAccountNumber, double amount){
       getAccount(userAccountNumber).debit(amount);
   }
}

Source code: Transaction
/**
 * Write a description of class Transaction here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public abstract class Transaction
{
   private int accountNumber;
   private Screen screen;
   private BankDatabase bankDatabase;
   public Transaction(int userAccountNumber, Screen atmScreen, BankDatabase atmBankDatabase){
       accountNumber = userAccountNumber;
       screen = atmScreen;
       bankDatabase = atmBankDatabase;
   }
   public int getAccountNumber(){
       return accountNumber;
   }
   public Screen getScreen(){
       return screen;
   }
   public BankDatabase getBankDatabase(){
       return bankDatabase;
   }
   abstract public void execute();
}

Source code: BalanceInquiry
/**
 * Write a description of class BalanceInquiry here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class BalanceInquiry extends Transaction
{
   public BalanceInquiry(int userAccountNumber, Screen atmScreen, BankDatabase atmBankDatabase){
       super( userAccountNumber, atmScreen, atmBankDatabase );
   }
   @Override
   public void execute()
   {
       BankDatabase bankDatabase = getBankDatabase();
       Screen screen = getScreen();
       double availableBalance = bankDatabase.getAvailableBalance(getAccountNumber());
       double totalBalance = bankDatabase.getTotalBalance(getAccountNumber());
       
       screen.displayMessageLine("\nBalance Information:");
       screen.displayMessage(" - Available balance: ");
       screen.displayDollarAmount(availableBalance);
       screen.displayMessage("\n - Total balance: ");
       screen.displayDollarAmount(totalBalance);
       screen.displayMessageLine("");
   }
}

Source code: Withdrawal
/**
 * Write a description of class Withdrawal here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
public class Withdrawal extends Transaction
{
   private int amount;
   private Keypad keypad;
   private CashDispenser cashDispenser;
   
   private final static int CANCELED = 6;
   
   public Withdrawal(int userAccountNumber, Screen atmScreen, BankDatabase atmBankDatabase, Keypad atmKeypad, CashDispenser atmCashDispenser){
       super(userAccountNumber, atmScreen, atmBankDatabase);
       keypad = atmKeypad;
       cashDispenser = atmCashDispenser;
   }
   @Override
   public void execute(){
       boolean cashDispensed = false;
       double availableBalance;
       
       BankDatabase bankDatabase = getBankDatabase();
       Screen screen = getScreen();
       do{
           amount = displayMenuOfAmounts();
           if(amount!=CANCELED){
               availableBalance = bankDatabase.getAvailableBalance(getAccountNumber());
               if(amount<=availableBalance ){
                   if(cashDispenser.isSufficientCashAvailable(amount)){
                       bankDatabase.debit(getAccountNumber(), amount);
                       cashDispenser.dispenseCash(amount);
                       cashDispensed = true;
                   
                       screen.displayMessageLine("\nYour cash has been dispensed. Please take your cash now.");
                   }
                   else
                       screen.displayMessageLine("\nInsufficient cash available in the ATM.\n\nPlease choose a smaller amount.");
               }
               else{
                   screen.displayMessageLine("\nInsufficient funds in your account.\n\nPlease choose a smaller amount.");
               }
           }
           else{
               screen.displayMessageLine("\nCanceling transaction...");
               return;
           }
       }
       while(!cashDispensed);
   }
   private int displayMenuOfAmounts(){
       int userChoice = 0;
       Screen screen = getScreen();
       int[] amounts = {0, 20, 40, 60, 100, 200};
       while(userChoice==0){
           screen.displayMessageLine("\nWithdrawal Menu:");
           screen.displayMessageLine("1 - $20");
           screen.displayMessageLine("2 - $40");
           screen.displayMessageLine("3 - $60");
           screen.displayMessageLine("4 - $100");
           screen.displayMessageLine("5 - $200");
           screen.displayMessageLine("6 - Cancel transaction");
           screen.displayMessage("\nChoose a withdrawal amount: ");
           
           int input = keypad.getInput();
           
           switch(input){
               case 1:
               case 2:
               case 3:
               case 4:
               case 5:
                   userChoice = amounts[input];
                   break;
               case CANCELED:
                   userChoice = CANCELED;
                   break;
               default:
               screen.displayMessageLine("\nInvalid selection. Try again.");
           }
       }
       return userChoice;
   }
}

Source code: Deposit
/**
 * Write a description of class Deposit here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
public class Deposit extends Transaction
{
   private double amount;
   private Keypad keypad;
   private DepositSlot depositSlot;
   private final static int CANCELED = 0;
   public Deposit(int userAccountNumber, Screen atmScreen, BankDatabase atmBankDatabase, Keypad atmKeypad, DepositSlot atmDepositSlot){
       super(userAccountNumber, atmScreen, atmBankDatabase);
       keypad = atmKeypad;
       depositSlot = atmDepositSlot;
   }
   @Override
   public void execute(){
       BankDatabase bankDatabase = getBankDatabase();
       Screen screen = getScreen();
       amount = promptForDepositAmount();
       if(amount!=CANCELED){
           screen.displayMessage("\nPlease insert a deposit envelope containing ");
           screen.displayDollarAmount(amount);
           screen.displayMessageLine(".");
           
           boolean envelopeReceived = depositSlot.isEnvelopeReceived();
           if(envelopeReceived){
               screen.displayMessageLine("\nYour envelope has been received.\nNOTE: The money just deposited will not be available until we verify the amount of any enclosed cash and your checks clear.");
               bankDatabase.credit(getAccountNumber(), amount);
           }
           else{
               screen.displayMessageLine("\nYou did not insert an envelope, so the ATM has canceled your transaction.");
           }
       }
       else{
           screen.displayMessageLine("\nCanceling transaction...");
       }
   }
   private double promptForDepositAmount(){
       Screen screen = getScreen();
       screen.displayMessage("\nPlease enter a deposit amount in CENTS (or 0 to cancel): ");
       int input = keypad.getInput();
       if(input==CANCELED)
           return CANCELED;
       else{
           return(double) input/100;
       }
   }
}

Source code: ATMCaseStudy
/**
 * Write a description of class ATMCaseStudy here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
public class ATMCaseStudy
{
   public static void main(String[] args){
       ATM theATM = new ATM();
       theATM.run();
   }
}

Senin, 03 April 2017

Antrian Bank

Bank merupakan tempat berkumpulnya masyarakat untuk menyimpan atau pun mengambil uang. Sebelum melakukan transaksi biasanya nasabah diminta mengambil nomor antrian di mesin pencetak antrian.

Mesin pencetak antrian bank adalah system yang berfungsi untuk mengelola nomor urut antrian nasabah bank. Mesin ini mempunyai fungsi, mempermudah teller dan customer service, atau layanan lain pada bank tersebut, memanggil nasabah dan melayani sesuai dengan keperluan nasabah, pada masing-masing layanan.




Berikut adalah rancangan dari mesin tersebut:

BankQueue
##############################

---------------
+ BankQueue()
+ prepareGUI()
+ showButton()
##############################


tambah
##############################
- nomorT : int = 0
- antriT : int = 0
- nomorCS : int = 0
- antriCS : int= 0
---------------
+ show()
+ kurang(x : String)
##############################



Source code:
/**
 * Write a description of class BankQueue here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.awt.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;
import javax.swing.*;
public class BankQueue
{
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private tambah a;
   public BankQueue(){
       prepareGUI();
       this.a = new tambah();
   }
   public static void main(String[] args){
       BankQueue test = new BankQueue();
       test.showButton();
   }
   private void prepareGUI(){
       mainFrame = new JFrame("Bank Toto International, LTD");
       mainFrame.setSize(300,150);
       mainFrame.setLayout(new GridLayout(3, 1));
      
       mainFrame.addWindowListener(new WindowAdapter() {
           public void windowClosing(WindowEvent windowEvent){
               System.exit(0);
           }        
       });
       
       headerLabel = new JLabel("", JLabel.CENTER);        
       statusLabel = new JLabel("", JLabel.CENTER);    
       statusLabel.setSize(350,100);

       controlPanel = new JPanel();
       controlPanel.setLayout(new FlowLayout());

       mainFrame.add(headerLabel);
       mainFrame.add(controlPanel);
       mainFrame.add(statusLabel);
       mainFrame.setVisible(true);  
   }
   private void showButton(){
       headerLabel.setText("Welcome to Bank Toto International, LTD");
       
       JButton okButton = new JButton("Nasabah"); 
       JButton oceButton = new JButton("Pegawai"); 
       okButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               a.show();
           }          
       });
       oceButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               String pil= JOptionPane.showInputDialog("Tulis yang telah melayani\nTeller\n  atau\nCustomer Service");
               a.kurang(pil);
           }          
       });
       controlPanel.add(okButton);
       controlPanel.add(oceButton);
       mainFrame.setVisible(true);  
   }
}
class tambah
{
   public int nomorT=0;
   public int antriT=0;
   public int nomorCS=0;
   public int antriCS=0;
   public void show(){
       Date dNow = new Date();
       SimpleDateFormat ft = new SimpleDateFormat("E, dd.MM.yyyy   hh:mm:ss a");
       
       String pilihan = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Teller\n 2. Customer Service");
       char c = pilihan.charAt(0);
       
       if(c=='1'){
           String message0 = String.format("###################################\nBank Toto International, LTD\n\n"+ft.format(dNow)+"\n\nNomor Antrian Anda :\nTELLER\nA%d\n\nMohon menunggu hingga nomor dipanggil...\nJumlah antrian: %d nasabah.\n###################################", nomorT+1, nomorT-antriT);
           JOptionPane.showMessageDialog(null, message0);
           nomorT++;
       }
       else if(c=='2'){
           String message1 = String.format("###################################\nBank Toto International, LTD\n\n"+ft.format(dNow)+"\n\nNomor Antrian Anda :\nCUSTOMER SERVICE\nB%d\n\nMohon menunggu hingga nomor dipanggil...\nJumlah antrian: %d nasabah.\n###################################", nomorCS+1, nomorCS-antriCS);
           JOptionPane.showMessageDialog(null, message1);
           nomorCS++;
       }
       else{
           String message2 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
           JOptionPane.showMessageDialog(null, message2);
       }
    }
   public void kurang(String x){
       switch (x){
           case "Teller":
              if(nomorT-antriT<=0){
                  String message3 = String.format("Tidak ada antrian untuk %s", x);
                  JOptionPane.showMessageDialog(null, message3);
              }
              else{
                  antriT++;
                  String message4 = String.format("Berhasil mengurangi nasabah pada antrian %s.\nSisa nasabah yang belum mendapatkan pelayanan %d", x, nomorT-antriT);
                  JOptionPane.showMessageDialog(null, message4);
              }
              break;
           case "Customer Service":
               if(nomorCS-antriCS<=0){
                  String message5 = String.format("Tidak ada antrian untuk %s", x);
                  JOptionPane.showMessageDialog(null, message5);
              }
              else{
                  antriCS++;
                  String message6 = String.format("Berhasil mengurangi nasabah pada antrian %s.\nSisa nasabah yang belum mendapatkan pelayanan %d", x, nomorCS-antriCS);
                  JOptionPane.showMessageDialog(null, message6);
              }
              break;
           default:
              String message7 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
              JOptionPane.showMessageDialog(null, message7);
              break;
       }
   }
}


Hasilnya:

Pilihan Nasabah, untuk mencetak kartu antrian
Pilihan Pegawai, untuk tiap kali selesai melayani nasabah.



Apabila dipilih pada Nasabah, maka..


Untuk pilihan 1, yakni TELLER



Untuk pilihan 2, yakni CUSTOMER SERVICE



*nomor urutan akan terus bertambah


Apabila dipilih pada Pegawai, maka..



atau


Apabila ditulis Teller, maka..

Ketika ada nasabah yang mengantri lagi, jumlah antriannya tetap 6


Apabila ditulias Customer Service, maka..

Ketika ada nasabah yang mengantri lagi, jumlah antriannya tetap 8




#Revisi
Source code date:
/**
 * Write a description of class date here.
 * 
 * @author Davin Masasih - 5115100113
 * @version 0.1
 */
import java.util.*;
import java.text.*;
public class date
{
   public String getTanggal(){
       Date dNow = new Date();
       SimpleDateFormat ft = new SimpleDateFormat("E, dd.MM.yyyy   hh:mm:ss a");
       return ft.format(dNow);
   }
}

Source code Teller:
/**
 * Write a description of class Teller here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.util.*;
import java.text.*;
import javax.swing.*;
public class Teller
{
   private int nomorT=0;
   private int antriT=0;
   private date q;
   
   public void ticketT(){
       this.q = new date();
       String message1 = String.format("#######################################\nBank Toto International, LTD\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nTELLER\nA%d\n\nMohon menunggu hingga nomor dipanggil...\nJumlah antrian: %d nasabah.\n#######################################", nomorT+1, nomorT-antriT);
       JOptionPane.showMessageDialog(null, message1);
       nomorT++;
   }
   public void screenT(){
       antriT++;
       String message2 = String.format("Pelayanan:\nTELLER\nA%d\n\nBelum mendapatkan pelayanan %d nasabah.", nomorT-(nomorT-antriT),nomorT-antriT);
       JOptionPane.showMessageDialog(null, message2);
   }
}

Source code CustomerService:
/**
 * Write a description of class CustomerService here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.util.*;
import java.text.*;
import javax.swing.*;
public class CustomerService
{
   private int nomorCS=0;
   private int antriCS=0;
   private date q;

   Date dNow = new Date();
   SimpleDateFormat ft = new SimpleDateFormat("E, dd.MM.yyyy   hh:mm:ss a");
   
   public void ticketCS(){
       this.q = new date();
       String message1 = String.format("#######################################\nBank Toto International, LTD\n\n"+q.getTanggal()+"\n\nNomor Antrian Anda :\nCUSTOMER SERVICE\nB%d\n\nMohon menunggu hingga nomor dipanggil...\nJumlah antrian: %d nasabah.\n#######################################", nomorCS+1, nomorCS-antriCS);
       JOptionPane.showMessageDialog(null, message1);
       nomorCS++;
   }
   public void screenCS(){
       antriCS++;
       String message2 = String.format("Pelayanan:\nCUSTOMER SERVICE\nB%d\n\nBelum mendapatkan pelayanan %d nasabah.", nomorCS-(nomorCS-antriCS),nomorCS-antriCS);
       JOptionPane.showMessageDialog(null, message2);
   }
}

Source code bang:
/**
 * Write a description of class bang here.
 * 
 * @author Davin Masasih - 5115100113 
 * @version 0.1
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class bang
{
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;
   private Teller a;
   private CustomerService b;
   public bang(){
       prepareGUI();
       this.a = new Teller();
       this.b = new CustomerService();
   }
   public static void main(String[] args){
       bang test = new bang();
       test.showButton();
   }
   private void prepareGUI(){
       mainFrame = new JFrame("Bank Toto");
       mainFrame.setSize(300,150);
       mainFrame.setLayout(new GridLayout(3, 1));
      
       mainFrame.addWindowListener(new WindowAdapter() {
           public void windowClosing(WindowEvent windowEvent){
               System.exit(0);
           }        
       });
       
       headerLabel = new JLabel("", JLabel.CENTER);        
       statusLabel = new JLabel("", JLabel.CENTER);    
       statusLabel.setSize(350,100);

       controlPanel = new JPanel();
       controlPanel.setLayout(new FlowLayout());

       mainFrame.add(headerLabel);
       mainFrame.add(controlPanel);
       mainFrame.add(statusLabel);
       mainFrame.setVisible(true);  
   }
   private void showButton(){
       headerLabel.setText("Welcome to Bank Toto International, LTD");
       
       JButton nButton = new JButton("Nasabah"); 
       JButton pButton = new JButton("Pegawai"); 
       nButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){       
               String pilihan = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Teller\n 2. Customer Service");
               char c = pilihan.charAt(0);
               if(c=='1'){
                   a.ticketT();
               }
               else if(c=='2'){
                   b.ticketCS();
               }
               else{
                   String message2 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                   JOptionPane.showMessageDialog(null, message2);
               }
           }          
       });
       pButton.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               String pilihan = JOptionPane.showInputDialog("Silahkan pilih:\n 1. Teller\n 2. Customer Service");
               char c = pilihan.charAt(0);
               if(c=='1'){
                   a.screenT();
               }
               else if(c=='2'){
                   b.screenCS();
               }
               else{
                   String message7 = String.format("Pilihan yang Anda masukkan salah. Silahkan coba lagi...");
                   JOptionPane.showMessageDialog(null, message7);
               }
           }          
       });
       controlPanel.add(nButton);
       controlPanel.add(pButton);
       mainFrame.setVisible(true);  
   }
}

Implementasi Aplikasi Manajemen Surat