Nama : Edgar Andrew Hutauruk
NRP : 05111740000166
Kelas : PBO-B
Class ParkingMeter
Class InputReader
NRP : 05111740000166
Kelas : PBO-B
Class ParkingMeter
/**
* Write a description of class Reader here.
*
* @author (Edgar Andrew Hutauruk/05111740000166)
* @version (a version number or a date)
*/
import java.util.Calendar;
import java.util.Date;
public class ParkingMeter{
private InputReader reader;
private String JenisKendaraan, Nopol;
private int NoTiket = 0, TarifParkir, SaldoAwal;
private Calendar calendar;
private Date today, tomorrow;
public ParkingMeter() {
reader = new InputReader();
calendar = Calendar.getInstance();
}
public void start() {
NoTiket++;
System.out.println("Selamat datang");
System.out.println("Silakan masukkan jenis kendaraan Anda.");
System.out.println("Tekan '1' untuk mobil");
System.out.println("Tekan '2' untuk motor");
JenisKendaraan = reader.getJenisKendaraan();
switch(JenisKendaraan) {
case "Mobil": TarifParkir = 5000; break;
case "Motor": TarifParkir = 2000; break;
}
System.out.println("\nMasukkan 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();
}
private void printKarcis() {
System.out.println("--------------------------------");
System.out.println("Nomor Tiket : " + NoTiket);
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("Saldo Awal : Rp" + SaldoAwal);
System.out.println("Tarif Parkir : Rp" + TarifParkir);
System.out.println("--------------------------------");
}
}
Class InputReader
/**
* Write a description of class Reader here.
*
* @author (Edgar Andrew Hutauruk/05111740000166)
* @version (a version number or a date)
*/
import java.util.Scanner;
public class InputReader {
public String getString() {
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;
}
public String getJenisKendaraan() {
int input = getInt();
String jenis = null;
switch(input) {
case 1: jenis = "Mobil"; break;
case 2: jenis = "Motor"; break;
}
return jenis;
}
}
Komentar
Posting Komentar