Sunday, October 14, 2018

ETS: Membuat Karcis Parkir Elektronik


Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A

Ini adalah ETS untuk membuat Karcis Parkir Elektronik menggunakan Java

Berikut adalah class dan source codenya:

A) Main
 public class Main  
 {  
   public static void main(String args[])  
   {  
     ParkingMachine mesinparkir = new ParkingMachine();  
     mesinparkir.run();  
   }  
 }  

B) ParkingMachine
/**
 * Write a description of class ParkingMachine here.
 *
 * @author Muhammad Naufal Refadi
 * @version 15-10-2018
 */
public class ParkingMachine
{
    private Database database;
    private Keypad keypad;
    private Karcis karcis;
    private Display display;
    private Jenis jenis;
    public ParkingMachine()
    {
        jenis = new Jenis(); 
        database = new Database();
        keypad = new Keypad();
        display = new Display();
    }
    
    public void run()
    {
        while(true)
        {
        
            display.screenMessage("Pilih Jenis Parkir");
            display.screenMessage("1. Mobil");
            display.screenMessage("2. Sepeda Motor");
            int accjenis=keypad.getInput();
            int cost=jenis.cekJenis(accjenis);
            String type=jenis.cekKendaraan(cost);
            display.screenMessage("Masukkan plat nomor kendaraan anda");
            String platnomor=keypad.getInputString();
            display.screenMessage("Tempelkan kartu anda");
            int cekNum = keypad.getInput();
            if(database.cekUser(cekNum))
            {
                if(database.getAccountBalance(database.cekAccount(cekNum)) >= cost)
                {
                    database.pay(database.cekAccount(cekNum), cost);
                    karcis = new Karcis(database.cekAccount(cekNum).getBalance(),cost,platnomor,type);
                    karcis.print();
                    display.screenMessage("Silahkan mengambil karcisnya");
                    display.screenMessage("Berikan 1 karcis kepada jukir dan simpan 1 karcisnya");
                    display.screenMessage("Terima kasih telah menggunakan layakan kami\n");
                    
                }
                else
                {
                    display.screenMessage("Sisa Saldo anda tidak mencukupi\n");
                }
            }
            else
            {
                display.screenMessage("Nomor Kartu anda tidak ditemukan. Silahkan ulangi sekali lagi\n");
            }
    }
    
 }
}

c) Jenis
public class Jenis
{  
    public int cekJenis(int jenis)
    {
        int harga=0;
        if(jenis==1){harga=3000;}
        else if(jenis==2){harga=2000;}
        return harga;
    }
    public String cekKendaraan(int price)
    {    String trans="";
        if(price==3000){ trans="MOBIL";}
        else if(price==2000){trans="Sepeda Motor";}
        return trans;
    }
   
}

d) Database
 public class Database  
 {    
   private Account accounts[];  
   public Database()  
   {  
     accounts = new Account[7];  
     accounts[0] = new Account(38321,32000);  
     accounts[1] = new Account(94821,103000);  
     accounts[2] = new Account(19230,100000);  
     accounts[3] = new Account(49234, 40500);  
     accounts[4] = new Account(82019, 55000);  
     accounts[5] = new Account(59120, 89000);  
     accounts[6] = new Account(45352, 70000);  
   }  
   public Account cekAccount(int AccountNumber)  
   {  
     for(Account currentAccount : accounts)  
     {  
       if ( currentAccount.getAccountNumber() == AccountNumber ) return currentAccount;  
     }  
     return null;  
   }  
   public boolean cekUser(int UserAccount)  
   {  
     Account userAccount = cekAccount(UserAccount);  
     if(userAccount == null){return false;}  
     return true;  
   }  
   public int getAccountBalance(Account useraccount)  
   {  
     return useraccount.getBalance();  
   }  
   public void pay(Account useraccount, int amount)  
   {  
     useraccount.pay(amount);  
   }  
 }  
e) Account
 public class Account  
 {  
   private int accountNumber;  
   private int balance;  
   public Account(int AccountNumber, int Balance)  
   {  
     accountNumber = AccountNumber;  
     balance = Balance;  
   }  
   public int getBalance()  
   {  
     return balance;  
   }  
   public int getAccountNumber()  
   {  
     return accountNumber;  
   }  
   public void pay(int Cost)  
   {  
     balance = balance - Cost;  
   }  
 }  

f) Display
 public class Display  
 {  
   public void screenMessage(String message)  
   {   
     System.out.println(message);   
   }  
 }  

g) Keypad
 import java.util.Scanner;  
 public class Keypad  
 {  
   private Scanner input;  
   public Keypad()  
   {   
     input = new Scanner(System.in);   
   }  
   public int getInput()  
   {   
     return input.nextInt();   
   }  
   public String getInputString()   
   {   
    Scanner sc = new Scanner(System.in);   
    String input = sc.nextLine();   
    return input;   
   }   
 }   
h) Karcis
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Karcis
{
    int balance;
    int price;
    String plat;
    String transp;
    private Date date;
    private DateFormat dateFormat;
    public Karcis(int Balance, int Price,String Plat,String Transp)
    {
        balance = Balance;
        price = Price;
        plat=Plat;
        transp=Transp;
        dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        date = new Date();
    }
    public void print()
    {
        System.out.println("###############################################");
        System.out.println("#KOTA SURABAYA                                #");
        System.out.println("#Parkir ELektronik Taman Bungkul              #");
        System.out.println("#Jenis Kendaraan: " +transp+"                       #");
        System.out.println("#Plat Nomor: " +plat+"                        #");
        System.out.println("#Tanggal Transaksi: " + dateFormat.format(date)+"       #");
        System.out.println("#Biaya Parkir: " + price+"                           #");
        System.out.println("#Sisa Saldo: " + balance+"                            #");
        System.out.println("###############################################");
    }
}

Dan inilah hasil Screenshot Bagan Class


Ini adalah hasil output jika salah membaca no.kartu karena beberapa alasan seperti kartu tidak terdaftar.








No comments:

Post a Comment