Membuat Sistem E-Parking
Nama : Haikal Almaz Said
NRP : 05111740000068
Kelas : PBO A
pada postingan kali ini, saya akan membagikan hasil Membuat Sistem E-Parking dalam Java, berikut Source Code dan screen shot dari Hasil tersebut :
import java.util.Scanner;
/**
* ini merupakan class main
*
* @author (Haikal Almaz Said)
* @version (15/10/2018)
*/
public class mainTicket
{
public static int main()
{
Scanner sc = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
int start,cost, menu, jenis, lama, insertSald, biaya, saldo;
System.out.println("Selamat Datang di Sistem Parkir Elektronik \nTekan 1 untuk mulai");
start=scan.nextInt();
while(start==1)
{
lama = 0;
System.out.println("Pilih Menu");
System.out.println("1. Buat Karcis Parkir");
System.out.println("2. Exit");
menu=scan.nextInt();
switch(menu)
{
case 1:
System.out.println("Masukkan Nomor Polisi Anda");
String nopol = sc.next();
System.out.println("Pilih Jenis Kendaraan");
System.out.println("1. Truk");
System.out.println("2. Mobil");
System.out.println("3. Sepeda Motor");
System.out.println("4. Cancel");
jenis = scan.nextInt();
TicketMachine ticket = new TicketMachine(jenis);
ticket.getNopol(nopol);
cost = ticket.getPrice();
if(jenis==4) break;
else
{
System.out.println("Masukkan Lama Parkir (dalam Jam)");
lama = scan.nextInt();
biaya = ticket.getTotal(lama);
System.out.println("Tempelkan Kartu Anda (Masukkan Isi Saldo Kartu Anda)");
saldo = scan.nextInt();
ticket.insertMoney(saldo);
if(biaya>saldo) System.out.println("Maaf Saldo Anda Tidak Mencukupi");
else ticket.printTicket();
}
break;
case 2:
return 0;
}
}
return 0;
}
}
2. Class TicketMachine
/**
* ini merupakan class Ticket machine
*
* @author (Haikal Almaz Said)
* @version (15/10/2018)
*/
public class TicketMachine
{
private int price; private int balance; private int total; private String nopol;
private String kendara; private int lama;
public TicketMachine(int jenis)
{
if(jenis==1)
{
price = 5000;
kendara = "Truk";
}
else if(jenis==2)
{
price = 3000;
kendara = "Mobil";
}
else if(jenis==3)
{
price = 2000;
kendara = "Sepeda Motor";
}
balance = 0; total=0;
}
public void getNopol(String nopoli)
{
String nopol1=nopoli;
nopol=nopol1;
}
public int getPrice()
{
return price;
}
public int getTotal(int lamaPark)
{
total = price*lamaPark;
lama = lamaPark;
return total;
}
public int getBalance()
{
return balance;
}
public void insertMoney(int amount)
{
balance=balance+amount;
}
public void printTicket()
{
System.out.println("###################################");
System.out.println("# Ticket Parkir Meteran Surabaya");
System.out.println("# Kendaraan : "+kendara);
System.out.println("# Nomor Plat : "+nopol);
System.out.println("# Tarif : Rp. "+total);
System.out.println("# Lama Parkir : "+lama+" Jam");
balance = balance-total;
System.out.println("# Sisa Saldo : "+balance);
System.out.println("###################################");
System.out.println();
balance=0;
}
}
3. Screenshot
t
No comments:
Post a Comment