1. Class Window
2. Source Code
ParkingSystem Class
/**
* ParkingSystem Class.
*
* @author (Arino Jenynof)
* @version (201801015)
*/
import java.util.Scanner;
public class ParkingSystem
{
public static void main(String[] args)
{
int jenisKendaraan;
int bayar;
String noPolisi;
String waktuDatang;
String waktuKeluar;
Scanner inp = new Scanner(System.in);
EntryGate masuk = new EntryGate();
ExitGate keluar = new ExitGate();
System.out.println("Masuk Parkiran BlueJ");
System.out.println("Tarif sekali masuk");
System.out.println("5000 (Mobil)");
System.out.println("3000 (Motor)");
System.out.println("Pilih jenis kendaraan");
System.out.println("1. Mobil");
System.out.println("2. Motor");
jenisKendaraan = inp.nextInt();
while (jenisKendaraan != 1 && jenisKendaraan != 2)
{
System.out.println("Salah nomor, masukkan lagi");
jenisKendaraan = inp.nextInt();
}
System.out.println("Masukkan nomor kendaraan (tanpa spasi)");
noPolisi = inp.next();
System.out.println("Masukkan waktu datang");
waktuDatang = inp.next();
masuk.printTicket(noPolisi, waktuDatang);
System.out.println("Silahkan Masuk");
System.out.println("\n/*******************************/");
System.out.println("\nKeluar Parkiran BlueJ");
if (jenisKendaraan == 1)
{
System.out.println("Anda harus membayar 5000, bayar? (y/n)");
bayar = inp.nextInt();
while (bayar < 5000)
{
System.out.println("Anda masih kurang " + (5000 - bayar));
bayar += inp.nextInt();
}
keluar.printTicket(noPolisi, waktuDatang, jenisKendaraan);
System.out.println("Silahkan Keluar");
}
else
{
System.out.println("Anda harus membayar 3000, bayar berapa?");
bayar = inp.nextInt();
while (bayar < 3000)
{
System.out.println("Anda masih kurang " + (3000 - bayar));
bayar += inp.nextInt();
}
keluar.printTicket(noPolisi, waktuDatang, jenisKendaraan);
System.out.println("Silahkan Keluar");
}
}
}
EntryGate Class
/**
* EntryGate Class.
*
* @author (Arino Jenynof)
* @version (20181015)
*/
public class EntryGate
{
private TicketDispenser disp;
public EntryGate()
{
disp = new TicketDispenser();
}
public void printTicket(String noPolisi, String waktu)
{
disp.print(noPolisi, waktu);
}
}
ExitGate Class
/**
* ExitGate Class.
*
* @author (Arino Jenynof)
* @version (20181015)
*/
public class ExitGate
{
private TicketDispenser disp;
public ExitGate()
{
disp = new TicketDispenser();
}
public void printTicket(String noPolisi, String waktu, int type)
{
disp.print(noPolisi, waktu, type);
}
}
TicketDispenser Class
/**
* TicketDispenser Class.
*
* @author (Arino Jenynof)
* @version (20181015)
*/
public class TicketDispenser
{
public void print(String noPolisi, String waktu)
{
System.out.println("===========================================");
System.out.println("\t\tTiket Masuk");
System.out.println("No Polisi : " + noPolisi);
System.out.println("Waktu Datang: " + waktu);
System.out.println("===========================================");
}
public void print(String noPolisi, String waktu, int jenisKendaraan)
{
System.out.println("===========================================");
System.out.println("\t\tTiket Keluar");
System.out.println("No Polisi : " + noPolisi);
System.out.println("Waktu Keluar: " + waktu);
if (jenisKendaraan == 1)
{
System.out.println("Bayar : 5000 (Mobil)");
}
else
{
System.out.println("Bayar : 3000 (Motor)");
}
System.out.println("===========================================");
}
}
3. Output
Comments
Post a Comment