Manless Parking System
1. MainMachine
import java.util.Scanner;
/**
* Manless parking system.
*
* @author Christine Amelia
* @version (UTS-15/10/2018)
*/
public class MainMachine
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int vehicle,duration;
String nopolis;
System.out.println("\t\tParking System");
System.out.println("----------------------");
System.out.println("Pilih kendaraan anda: ");
System.out.println("1. Motor");
System.out.println("2. Mobil");
System.out.println("3. Bus/Truk");
System.out.print("Kendaraan: ");
vehicle = scan.nextInt();
Ticket ticket= new Ticket(vehicle);
System.out.print("Masukkan nomor polisi kendaraan anda : ");
nopolis = scan.next();
ticket.insertnopolis(nopolis);
System.out.print("Masukkan durasi parkir (jam): ");
duration = scan.nextInt();
ticket.insertduration(duration);
System.out.println("----------------------------");
if(vehicle == 1)
{
System.out.println("Tarif : Rp 2000/2 jam. Tarif sekarang: Rp " + duration*2000);
}
if(vehicle == 3)
{
System.out.println("Tarif : Rp 4000/2 jam. Tarif sekarang: Rp "+duration*4000);
}
else if(vehicle == 2)
{
System.out.println("Tarif : Rp 5000/2 jam. Tarif sekarang: Rp " + duration*5000);
}
System.out.println("Ketik 1 jika ingin mencetak karcis");
int type = scan.nextInt();
if(type==1)
{
ticket.printTicket();
}
}
}
2. Ticket
/**
* Manless parking system.
*
* @author Christine Amelia
* @version (UTS-15/10/2018)
*/
public class Ticket
{
int pricemotor = 2000;
int pricemobil = 4000;
int pricebus = 5000;
int duration;
String nopolis;
int vehicle;
public Ticket(int jenis)
{
vehicle = jenis; //1 motor, 2 mobil, 3 bus
}
public void insertnopolis(String nopolisi)
{
nopolis = nopolisi;
}
public void insertduration(int waktu)
{
duration = waktu;
}
public void printTicket()
{
if(vehicle == 1)
{
System.out.println("Parking System");
System.out.println("-------------------------");
System.out.println("Durasi parkir: " + duration + " jam");
System.out.println("Kendaraan: Motor");
System.out.println("Nomor polisi kendaraan: " + nopolis);
System.out.println("Tarif: Rp " + pricemotor*duration);
}
if(vehicle == 2)
{
System.out.println("Parking System");
System.out.println("-----------------------");
System.out.println("Kendaraan : Mobil");
System.out.println("Nomor polisi kendaraan: " + nopolis);
System.out.println("Tarif: Rp "+pricemobil*duration);
}
else if(vehicle == 3)
{
System.out.println("Parking System");
System.out.println("------------------------");
System.out.println("Durasi parkir: " + duration);
System.out.println("Kendaraan: Bus/Truk");
System.out.println("Nomor polisi kendaraan: " + nopolis);
System.out.println("Tarif: Rp " + pricebus*duration);
}
}
}
Tidak ada komentar:
Posting Komentar