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