ETS PEMROGRAMAN BERORIENTASI OBJEK
Karina Soraya P
05111740000003
PBO - B
05111740000003
PBO - B
SISTEM PARKIR ELEKTRONIK
4. Gambarkan skema kelas untuk mengimplementasikannya beserta field dan methodnya
Terdapat 6 kelas :
- Park : menjalankan proses parkir elektronik
- Parking : berisi pengaturan parkir elektronik
- Account : yang berisi pengaturan akun dari kartu parkir
- Screen : untuk menampilkan prosesnya
- Emoney Database : untuk mengatur saldo dari kartu parkir elektronik
- Keypad : untuk input data
5. Implementasikan program simulasinya
- Source Code Account
/**
* Write a description of class Account here.
*
* @author Karina Soraya P
* @version 1.0/20181015
*/
public class Account
{
private int accountID;
private double balance;
public Account(int accountID, double balance)
{
this.accountID = accountID;
this.balance = balance;
}
public int getAccountID()
{
return accountID;
}
public void pay(double amount)
{
balance -= amount;
System.out.println("Rp. "+balance);
}
public double getBalance()
{
return balance;
}
}
- Source Code EMoney Database
/**
* Write a description of class EMoneyDatabase here.
*
* @author Karina Soraya P
* @version 1.2/20181015
*/
public class EMoneyDatabase
{
private Account[] accounts;
public EMoneyDatabase()
{
accounts = new Account[3];
accounts[0] = new Account(12345678, 200000);
accounts[1] = new Account(87654321, 300000);
accounts[2] = new Account(29121996, 5000);
}
public Account getAccount(int accountID)
{
for (Account currentAccount : accounts)
{
if (currentAccount.getAccountID() == accountID)
return currentAccount;
}
return null;
}
}
- Source Code Keypad
/**
* Write a description of class Keypad here.
*
* @author Karina Soraya P
* @version 1.5/20181015
*/
import java.util.Scanner;
public class Keypad
{
private Scanner input;
public Keypad()
{
input = new Scanner(System.in);
}
public int getInput()
{
return input.nextInt();
}
}
- Source Code Screen
/**
* Write a description of class Screen here.
*
* @author Karina Soraya P
* @version 1.4/20181015
*/
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Screen
{
public void displayMessage(String string)
{
System.out.print(string);
}
public void displayMessageLine(String string)
{
System.out.println(string + "\n");
}
public void displayRupiah(double money)
{
System.out.print("Rp. " + money+ "\n");
}
public void displayCurrentTime() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE , dd/MM/yyyy HH:mm:ss");
System.out.println( sdf.format(cal.getTime()) );
}
}
- Source Code Park
/**
* Write a description of class PARK here.
*
* @author Karina Soraya P
* @version 1.3/20181015
*/
public class PARK
{
public static void main(String[] args)
{
PARKING gto = new PARKING();
gto.run();
}
}
- Source Code Parking
/**
* Write a description of class PARKING here.
*
* @author Karina Soraya P
* @version 1.1/20181015
*/
public class PARKING
{
private Account currentAccount;
private Keypad keypad;
private Screen screen;
private double bill;
private EMoneyDatabase eMoneyDatabase;
public PARKING()
{
currentAccount = null;
keypad = new Keypad();
screen = new Screen();
bill = 10000;
eMoneyDatabase = new EMoneyDatabase();
}
public void run() {
while (true)
{
while (currentAccount == null)
{
displayGetAccount();
}
screen.displayMessageLine("");
if (currentAccount.getBalance() >= bill)
{
printStruk();
} else {
screen.displayMessageLine("Saldo anda tidak mencukupi untuk membayar biaya tol.");
screen.displayMessage("Saldo anda: ");
screen.displayRupiah(currentAccount.getBalance());
}
currentAccount = null;
}
}
public void displayGetAccount()
{
screen.displayMessageLine("===========Selamat Datang!===========");
screen.displayMessage("Biaya Parkir: ");
screen.displayRupiah(bill);
screen.displayMessage("=========================================\n");
screen.displayMessageLine("Masukkan ID akun anda untuk membayar biaya parkir");
screen.displayMessage("ID Akun: ");
currentAccount = eMoneyDatabase.getAccount(keypad.getInput());
screen.displayMessage("=========================================\n");
}
public void printStruk()
{
screen.displayMessageLine("===========ROXY SQUARE===========");
screen.displayMessage("=========================================\n");
screen.displayCurrentTime();
screen.displayMessage("=========================================\n");
screen.displayMessage("Biaya Parkir: ");
screen.displayRupiah(bill);
screen.displayMessage("=========================================\n");
screen.displayMessage("Sisa saldo: ");
currentAccount.pay(bill);
screen.displayMessage("=========================================\n");
screen.displayMessageLine("Terima Kasih Telah Mengunjungi Roxy Square");
screen.displayMessage("=========================================\n");
}
}
- Hasil Implementasi
saat masuk, kita memasukkan ID lalu palang parkir terbuka
Komentar
Posting Komentar