UTS PBO A

Nama : Ifta Jihan N
NRP : 05111740000034
Kelas : PBO A

Berikut ini adalah simulator dari parkir meter untuk kendaraan. Parkir mobil dikenakan tarif Rp 5000/jam dan parkir motor dikenakan tarif Rp 3000/jam.

Terdapat 2 class yaitu Main dan Ticket.

1. Main

 /**  
  * Write a description of class main here.  
  *  
  * @author Ifta Jihan N (05111740000034)  
  * PBO A 15/10/2018  
  */  
 import java.util.Scanner;  
 public class main  
 {  
   public static void main(String args[])  
   {  
     Scanner scan = new Scanner(System.in);  
     int kendaraan, saldo, durasi;  
     String plat;  
     System.out.println("Dinas Perhubungan Kota Surabaya");  
     System.out.println("===============================");  
     System.out.println("Pilih kendaraan anda: ");  
     System.out.println("1. Mobil");  
     System.out.println("2. Motor");  
     System.out.print("Kendaraan: ");  
     kendaraan = scan.nextInt();  
     Ticket ticket= new Ticket(kendaraan);  
     System.out.print("Masukkan saldo anda: Rp ");  
     saldo = scan.nextInt();  
     ticket.insertsaldo(saldo);  
     System.out.print("Masukkan nomor plat anda : ");  
     plat = scan.next();  
     ticket.insertplat(plat);  
     System.out.print("Masukkan durasi parkir (jam): ");  
     durasi = scan.nextInt();  
     ticket.insertdurasi(durasi);  
     System.out.println("===============================");  
     if(kendaraan == 1) {  
       System.out.println("Tarif : Rp 5000/jam. Tarif sekarang: Rp " + durasi*5000);  
     }  
     else if(kendaraan == 2){  
       System.out.println("Tarif : Rp 3000/jam. Tarif sekarang: Rp " + durasi*3000);  
     }  
     System.out.println("Tempel kartu elektronik anda untuk membayar");  
     System.out.println("Ketik 1 jika ingin mencetak karcis");  
     int ketik = scan.nextInt();  
     if(ketik==1)   
     {ticket.printTicket();}  
   }  
 }  

2. Ticket

 /**  
  * Write a description of class Ticket here.  
  *  
  * @author Ifta Jihan N (05111740000034)  
  * PBO A 15/10/2018  
  */  
 public class Ticket  
 {  
   private int pricecar = 5000;  
   private int pricemotor = 3000;  
   private int balance;  
   private int durasi;  
   private String plat;  
   private int kendaraan;  
   public Ticket(int jenis)  
   {  
     kendaraan = jenis; //1 mobil, 2 motor  
   }  
   public void insertplat(String platno)  
   {  
     plat = platno;  
   }  
   public void insertdurasi(int lama)  
   {  
     durasi = lama;  
   }  
   public void insertsaldo(int saldo)  
   {  
       balance = saldo;  
   }  
   public void printTicket()  
   {   
     if(kendaraan == 1)  
     {  
       if (balance > 0)  
       {  
         if (balance >= pricecar*durasi)  
         {  
           System.out.println('\u000C');  
           System.out.println("Dinas Perhubungan Kota Surabaya");  
           System.out.println("===============================");  
           System.out.println("Durasi parkir: " + durasi + " jam");  
           System.out.println("Kendaraan: Mobil");  
           System.out.println("Plat nomor: " + plat);   
           System.out.println("Tarif: Rp " + pricecar*durasi);  
           int sisa1 = balance - pricecar*durasi;  
           System.out.println("Saldo: Rp " + sisa1);  
         }  
       }  
       else  
       {  
         System.out.println("Saldo anda tidak cukup");  
       }  
     }  
     else if(kendaraan == 2)  
     {  
       if (balance > 0)  
       {  
         if (balance >= pricemotor*durasi)  
         {  
           System.out.println('\u000C');  
           System.out.println("Dinas Perhubungan Kota Surabaya");  
           System.out.println("===============================");  
           System.out.println("Durasi parkir: " + durasi);  
           System.out.println("Kendaraan: Motor");  
           System.out.println("Plat nomor: " + plat);   
           System.out.println("Tarif: Rp " + pricemotor*durasi);  
           int sisa2 = balance - pricemotor*durasi;  
           System.out.println("Saldo: Rp " + sisa2);  
         }  
       }  
       else  
       {  
         System.out.println("Saldo anda tidak cukup");  
       }  
     }  
   }   
 }  


Hasil:



Comments

Popular Posts