Langsung ke konten utama

UTS Parking Meter

Hai semuanya. Pos ini berisi tentang cara mengimplementasikan ke dalam bahasa Java sebuah mesin parkir elektronik. Sebagai contoh, coba lihat Mesin Parkir Elektronik yang telah dikembangkan oleh Dinas Perhubungan Kota Surabaya di sekitar Taman Bungkul.




Proyek ini menggunakan 2 class, di antaranya:
  1. ParkingMeter
  2. InputReader

Berikut source codenya:
  1. ParkingMeter


       
     /**  
      * Class ini untuk class inti(main).  
      *  
      * @author (Elkana Hans Widersen/05111740000127/PBO A)  
      * @version (15/10/2018)  
      */  
       
     import java.util.Calendar;  
     import java.util.Date;  
     public class ParkingMeter{  
       private InputReader reader;  
       private String TerminalID, JenisKendaraan, Nopol;  
       private int NoTiket = 0, TarifParkir, SaldoAwal;  
       private Calendar calendar;  
       private Date today, tomorrow;  
         
       public ParkingMeter() {  
         reader = new InputReader();  
         calendar = Calendar.getInstance();  
         TerminalID = "00000001";  
       }  
         
       /**  
        * Memulai mesin parkir meter.  
        */  
       public void start() {  
         NoTiket++;  
         System.out.println("Selamat datang di Taman Bungkul!");  
         System.out.println("Silakan masukkan jenis kendaraan Anda.'1' untuk mobil, '2' untuk motor.");  
         JenisKendaraan = reader.getJenisKendaraan();  
         switch(JenisKendaraan) {  
           case "Mobil": TarifParkir = 3000; break;  
           case "Motor": TarifParkir = 1000; break;  
         }  
         System.out.println("\nSilakan masukkan nomor plat Anda.");  
         Nopol = reader.getString();  
         System.out.println("\nMasukkan saldo awal Anda.");  
         SaldoAwal = reader.getInt();  
         today = calendar.getTime();  
         calendar.add(Calendar.DAY_OF_YEAR, 1);  
         tomorrow = calendar.getTime();  
         System.out.println("\nAmbil tiket Anda.\n");  
         printKarcis();  
       }  
         
       /**  
        * Mencetakkan karcis parkir.  
        */  
       private void printKarcis() {  
         System.out.println("###############################");  
         System.out.println("DINAS PERHUBUNGAN KOTA SURABAYA");  
         System.out.println("Nomor Tiket : " + NoTiket);  
         System.out.println("Terminal ID : " + TerminalID);  
         System.out.println("Waktu Parkir : " + today);  
         System.out.println("Waktu Berakhir : " + tomorrow);  
         System.out.println("Jenis Kendaraan : " + JenisKendaraan);  
         System.out.println("Nomor Polisi : " + Nopol);  
         System.out.println("Tarif Parkir : Rp" + TarifParkir);  
         System.out.println("Saldo Awal : Rp" + SaldoAwal);  
         System.out.println("###############################");  
       }  
     }  
       
    
  2. InputReader


       
     /**  
      * Class ini untuk menangkap input.  
      *  
      * @author (Elkana Hans Widersen/05111740000127/PBO A)  
      * @version (15/10/2018)  
      */  
     import java.util.Scanner;  
     public class InputReader {  
       /**  
        * Untuk menangkap string.  
        */  
       public String getString() {  
         Scanner sc = new Scanner(System.in);  
         String input = sc.nextLine();  
         return input;  
       }  
         
       /**  
        * Untuk menangkap integer.  
        */  
       public int getInt() {  
         Scanner sc = new Scanner(System.in);  
         int input = sc.nextInt();  
         return input;  
       }  
         
       /**  
        * Untuk menentukan jenis kendaraan dari input integer.  
        */  
       public String getJenisKendaraan() {  
         int input = getInt();  
         String jenis = null;  
         switch(input) {  
           case 1: jenis = "Mobil"; break;  
           case 2: jenis = "Motor"; break;  
         }  
         return jenis;  
       }  
     }  
       
    

Cara menggunakan:
  1. Klik kanan di box ParkingMeter dan klik new ParkingMeter(). Beri nama sesuka Anda.
  2. Klik kanan di box merah yang baru saja muncul, lalu klik start().

Kurang lebih hasilnya seperti ini.


Terima kasih dan tunggu pos selanjutnya.

Komentar

Postingan populer dari blog ini

Fox and Rabbit Simulator

Hi guys! I'm going to show you a Fox and Rabbit Simulator made in BlueJ. We're going to use these classes Simulator SimulatorView Location Field FieldStats Counter Randomizer Rabbit Fox Here is the source code of those classes: Simulator import java.util.Random; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.awt.Color; /** * A simple predator-prey simulator, based on a rectangular field * containing rabbits and foxes. * * @author Elkana Hans Widersen * @version 1.0 */ public class Simulator { /** * Constants representing configuration information for the simulation. */ private static final int def_width = 50; // The default width for the grid. private static final int def_depth = 50; // The default depth of the grid. private static final double foxProbability = 0.02; // The probability that a fo...

Tugas 1 PBO A

This is my biodata compiled in Java (first time usage). Check it out! /** * Program membuat biodata menggunakan Java - BlueJ * * Author : Elkana Hans W * Version 1 , Date : 3 September 2018 */ public class biodata{ public biodata(){ System.out.print("PBO-Tugas1\n"); System.out.print("Nama\t: Elkana Hans Widersen\n"); System.out.print("Kelas\t: PBO A\n"); System.out.print("Alamat Rumah: Merak III/P2-104 Rewwin\n"); System.out.print("Email\t: elknhns@gmail.com\n"); System.out.print("Blog\t: elkanahans.blogspot.com\n"); System.out.print("No HP/WA: 082143646716\n"); System.out.print("Twitter\t: @elknhns\n"); } }

Tugas PBO Psychological Support Chatbot

Hi! We're back again! This time I'm going to show you my recent project on making a chatbot for technical support, called Monokuro Boo. It's great for you if you have traumas, problems, distress, etc. I'm using 3 classes for this chatbot, which are: SupportSystem InputReader Responder These are the source code. Check it out! SupportSystem /** * The main class for the support system, consisting greetings template. * * @author (Elkana Hans Widersen) * @version (08.10.2018) */ public class SupportSystem { private InputReader reader; private Responder responder; /** * Creates a technical support system. */ public SupportSystem() { reader = new InputReader(); responder = new Responder(); } /** * Start the technical support system. This will print a * welcome message and enter into a dialog with the user, * until the user ends the dialo...