Sunday, October 14, 2018

ETS PBO - SIstem Parkir

7:58 PM Posted by Unknown No comments
 Class yang digunakan
  1. Class Vehicle, merupakan class untuk input jenis kendaraan, nopol, serta durasi parkir
  2. Class Input Reader, sebagai class untuk melakukan input
  3. Class ParkingMachine, merupakan class yang berupa mesin parkir, dimana class ini menjadi pusat pengaturan operasi-operasi dan obyek-obyek pada mesin

  • Class Vehicle
 public class Vehicle   
 {   
   private InputReader reader;   
   public int gvehicle = 0;   
   public int durasi = 0;   
   public String nopol;   
   public void createVehicle(){   
    reader = new InputReader();   
    gvehicle = getVehicle();   
    nopol = getNopol();   
    durasi = getDurasi();   
   }   
   public int getVehicle(){   
     System.out.println("Pilih jenis kendaraan anda:");   
     System.out.println("1. Motor");   
     System.out.println("2. Mobil");   
     int gvehicle = reader.getInt();   
    return gvehicle;   
   }   
   public String getNopol(){   
    System.out.println("Silakan masukkan nomor polisi kendaraan anda: ");   
     String nopol = reader.getInput();   
    return nopol;   
   }   
   public int getDurasi(){   
    System.out.println("Durasi Parkir (dalam jam):");   
    int durasi = reader.getInt();   
    return durasi;   
   }   
 }  

  • Class InputReader
 import java.util.Scanner;   
 public class InputReader   
 {   
    public String getInput()   
 {   
    Scanner sc = new Scanner(System.in);   
    String input = sc.nextLine();   
    return input;   
 }   
 public int getInt(){   
    Scanner sc = new Scanner(System.in);   
    int input = sc.nextInt();   
    return input;   
   }   
 }   

  • Class ParkingMachine
 import java.util.Scanner;   
 public class ParkingMachine   
 {   
   private InputReader reader;   
   private Vehicle vehicle;   
   private int biaya = 0;   
 public ParkingMachine()   
 {   
    reader = new InputReader();   
    vehicle = new Vehicle();   
 }   
 public void start()   
 {   
    printWelcome();   
    vehicle.createVehicle();   
    biaya = 2000*vehicle.gvehicle*vehicle.durasi;    
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );   
    System.out.println("Tekan enter untuk melanjutkan");   
    reader.getInput();   
    System.out.println("Silakan tempelkan kartu pembayaran anda");   
    System.out.println("Tekan enter untuk melanjutkan");  
    reader.getInput();   
    printTicket();   
 }   
 private void printWelcome(){   
    System.out.println("Selamat Datang");   
 }   
 public void printTicket(){    
    System.out.println("------------Tiket 1-----------");  
    System.out.println("---Sistem Parkir Elektronik---");   
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );    
    System.out.println("-------------------------------");   
    System.out.println();    
    System.out.println("------------Tiket 2-----------");  
    System.out.println("---Sistem Parkir Elektronik---");   
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );    
    System.out.println("------------------------------");   
   }   
 }  


Berikut tampilan workspace


 NB : tarif parkir yang dikenakan adalah Rp2000,- per jam

0 comments:

Post a Comment