PBO A - Evaluasi Tengah Semester

PBO - A
Pada kesempatan kali ini, saya membuat sistem parkir elektronik menggunaka BlueJ.
Disini saya menggunakan 2 kelas yaitu :

  • SistemParkir
  • intMain

  • SistemParkir
 /**  
  * Write a description of class SistemParkir here.  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 import java.util.Scanner;  
 public class SistemParkir  
 {  
   // instance variables - replace the example below with your own  
   public int price;  
   public int ab;  
   public String platMobil;  
   public int durasiParkir;  
   /**  
    * Constructor for objects of class SistemParkir  
    */  
   public SistemParkir(int ab1)  
   {  
     ab=ab1;  
     durasiParkir=0;  
     platMobil="";  
   }  
   public int price(int durasi){  
     int hargaparkir;  
     hargaparkir = 3000 + 2000*durasi;  
     return hargaparkir;  
   }  
   public void payment(){  
    System.out.println("Parkir Rektorat ITS ");   
    System.out.println("Pembayaran untuk" +platMobil);   
    System.out.println("Dengan durasi " + durasiParkir + " jam.");  
    System.out.println("Total harga = " +price);  
    System.out.println("Tempel kartu untuk membayar (ketik 100)");  
    System.out.println();   
   }  
   public void printKarcis(){  
    System.out.println("||||||||||||||||||||||||||||||||||||||||");  
    System.out.println("|| Karcis Parkir Gedung Rektorat ITS ||");  
    System.out.println("||  Pembayaran berhasil dilakukan!  ||");  
    System.out.println("||   Hati-hati dalam perjalanan!  ||");  
    System.out.println("||||||||||||||||||||||||||||||||||||||||");  
    System.out.println("|| Keterangan:            ||");  
    System.out.println("|| Nopol = " +platMobil);  
    System.out.println("|| Durasi Parkir = " +durasiParkir);  
    System.out.println("|| Total Harga = Rp." +price);  
    System.out.println("||||||||||||||||||||||||||||||||||||||||");  
   }  
   public String getPlat()  
   {  
     String test;  
     Scanner scan= new Scanner(System.in);  
     test=scan.next();  
     return test;  
   }  
 }  
  • intMain
 /**  
  * Write a description of class intMain here.  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 import java.util.Scanner;  
 public class intMain  
 {  
   public static void main(String args[])  
   {  
     Scanner scan= new Scanner(System.in);  
     int ab, durasii, price;  
     String platMobil;  
     ab=scan.nextInt();  
     SistemParkir Avanza=new SistemParkir(ab);  
     System.out.println("||||||||||||||||||||||||||||||||||||||||");  
     System.out.println("Masukkan Nopol kendaraan anda!");  
     Avanza.platMobil=Avanza.getPlat();  
     System.out.println("||||||||||||||||||||||||||||||||||||||||");  
     System.out.println("Masukkan Durasi parkir kendaraan anda!");  
     durasii=scan.nextInt();  
     Avanza.durasiParkir= durasii;  
     Avanza.price=3000+durasii*2000;  
     Avanza.payment();  
     int bayar;  
     bayar=scan.nextInt();  
     if(bayar==100)  
     {  
       Avanza.printKarcis();  
     }  
     else  
     {  
       System.out.println("Saldo tidak cukup, silahkan membayar ke juru parkir!");  
     }   
   }  
 }  

Maka hasilnya akan seperti ini:




Comments

Popular posts from this blog

APSI 1 - Analisa Sistem Informasi Lazada

Tugas 3 PBKK