PBO - ETS - e-Toll Study Case
1. Buatlah sketsa dan beri penjelasan rancangan kelas yang akan digunakan untuk membuat mesin GTO
- Rancangan class yang akan digunakan adalah:
- Ada class tersendiri untuk mengatur database pengguna e-Toll
- Ada class tersendiri untuk mengatur output (message dan errormassage)
- Ada class tersendiri untuk mengatur output hasil (bukti transaksi pembayaran)
- Ada class khusus untuk menghandle kegiatan transaksi (pengurangan saldo dan pengecekan saldo)
2. Buatlah rancangan output dari program yang akan dibuat
- Output untuk mengeluarkan pesan biasa, seperti
- Selamat Datang, Silahkan tempel kartu E-Toll anda
- Output untuk menghandle error, seperti
- User ID tidak diketahui!. Silahkan coba lagi
- Pembayaran gagal dilakukan! Silahkan cek saldo anda
- Output untuk menghandle best case, dalam hal ini pembayaran berhasil dilakukan, seperti
- Pembayaran berhasil dilakukan! Silahkan mengambil struk anda
- Output bukti transaksi
Output
- Rancangan class yang akan digunakan adalah:
- Ada class tersendiri untuk mengatur database pengguna e-Toll
- Ada class tersendiri untuk mengatur output (message dan errormassage)
- Ada class tersendiri untuk mengatur output hasil (bukti transaksi pembayaran)
- Ada class khusus untuk menghandle kegiatan transaksi (pengurangan saldo dan pengecekan saldo)
2. Buatlah rancangan output dari program yang akan dibuat
- Output untuk mengeluarkan pesan biasa, seperti
- Selamat Datang, Silahkan tempel kartu E-Toll anda
- Output untuk menghandle error, seperti
- User ID tidak diketahui!. Silahkan coba lagi
- Pembayaran gagal dilakukan! Silahkan cek saldo anda
- Output untuk menghandle best case, dalam hal ini pembayaran berhasil dilakukan, seperti
- Pembayaran berhasil dilakukan! Silahkan mengambil struk anda
- Output bukti transaksi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class DatabaseToll { | |
private ETollData[] eTollData; | |
public DatabaseToll() { | |
eTollData = new ETollData[2]; | |
eTollData[0] = new ETollData(1000, 100000); | |
eTollData[1] = new ETollData(1001, 5000); | |
} | |
private ETollData geteTollID(int eTollID) { | |
for (ETollData currentAccount : eTollData) { | |
if (currentAccount.geteTollID() == eTollID) | |
return currentAccount; | |
} | |
return null; | |
} | |
public boolean authenticateUser(int userAccountNumber) { | |
ETollData userAccount = geteTollID(userAccountNumber); | |
if (userAccount != null) | |
return true; | |
else | |
return false; | |
} | |
public double getAvailableBalance(int eTollID) { | |
return geteTollID(eTollID).getAvailableBalance(); | |
} | |
public void isPay(int eTollID, double amount) { | |
geteTollID(eTollID).isPay(amount); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class ETollData { | |
private int eTollID; | |
private double availableBalance; | |
public ETollData(int eTollID, double availableBalance) { | |
this.eTollID = eTollID; | |
this.availableBalance = availableBalance; | |
} | |
public double getAvailableBalance() { | |
return availableBalance; | |
} | |
public void isPay(double amount) { | |
availableBalance -= amount; | |
} | |
public int geteTollID() { | |
return eTollID; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
import java.util.Scanner; | |
public class GetInput { | |
private Scanner input; | |
public GetInput() { | |
input = new Scanner(System.in); | |
} | |
public int getInput() { | |
return input.nextInt(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class MainToll { | |
public static void main(String[] args) { | |
Toll runToll = new Toll(); | |
runToll.runToll(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class Pay extends Transaction { | |
int credit; | |
boolean isDone = false; | |
public Pay(int eTollID, ScreenToll screenToll, DatabaseToll databaseToll) { | |
super(eTollID, screenToll, databaseToll); | |
} | |
@Override | |
public void execute() { | |
double availableBalance; | |
ScreenToll screenToll = getScreen(); | |
DatabaseToll tollDatabase = getTollDatabase(); | |
PrintResult screenResult; | |
do { | |
availableBalance = tollDatabase.getAvailableBalance(geteTollID()); | |
if(availableBalance >= 5000) { | |
screenResult = new PrintResult(availableBalance - 5000); | |
tollDatabase.isPay(geteTollID(), 5000); | |
isDone = true; | |
screenToll.displayMessage("Pembayaran berhasil dilakukan! Silahkan mengambil struk anda\n"); | |
screenToll.displayMessage("Membuka gerbang ....\n\n\n"); | |
screenResult.displayPrint(); | |
} else { | |
screenToll.displayErrorMessage("Pembayaran gagal dilakukan! Silahkan cek saldo anda\n"); | |
isDone = true; | |
} | |
} while(!isDone); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
public class PrintResult { | |
double availableBalance; | |
public PrintResult(double availableBalance) { | |
this.availableBalance = availableBalance; | |
} | |
public void displayPrint() { | |
Calendar cal = Calendar.getInstance(); | |
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); | |
System.out.println("###########JASAMARGA###########"); | |
System.out.println("###########PALIMANAN###########\n"); | |
System.out.println(sdf.format(cal.getTime())); | |
System.out.println("Seri: xxxxxx"); | |
System.out.println("Asal Gerbang: 04 (Brebes Timur)\n"); | |
System.out.println("Gol-1 e-Toll Mandiri Rp. 5000.0"); | |
System.out.println("Sisa Saldo Rp. " + String.valueOf(availableBalance)); | |
System.out.println("###############################"); | |
System.out.println("###############################\n\n\n"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class ScreenToll { | |
public void displayMessage(String message) { | |
System.out.print(message); | |
} | |
public void displayErrorMessage(String message) { | |
System.out.print(message); | |
} | |
public void displayCredit(double amount) { | |
System.out.printf("$%,.2f", amount); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public class Toll { | |
private ScreenToll screenToll; | |
private GetInput getInput; | |
private DatabaseToll databaseToll; | |
private boolean userAuth = false; | |
private int accID; | |
public Toll() { | |
screenToll = new ScreenToll(); | |
getInput = new GetInput(); | |
databaseToll = new DatabaseToll(); | |
userAuth = false; | |
accID = 0; | |
} | |
public void runToll() { | |
while(true) { | |
while(!userAuth) { | |
screenToll.displayMessage("Selamat Datang!\n"); | |
authenticateUser(); | |
} | |
doTransaction(); | |
userAuth = false; | |
accID = 0; | |
} | |
} | |
private void authenticateUser() { | |
screenToll.displayMessage("Silahkan tempel kartu E-Toll anda\n"); | |
int eTollID = getInput.getInput(); | |
userAuth = databaseToll.authenticateUser(eTollID); | |
if (userAuth) | |
{ | |
accID = eTollID; | |
} else | |
screenToll.displayErrorMessage("User ID tidak diketahui!. Silahkan coba lagi\n"); | |
} | |
private void doTransaction() { | |
Transaction userTransaction = null; | |
boolean userDone = false; | |
while(!userDone) { | |
userTransaction = createTransaction(); | |
userTransaction.execute(); | |
userDone = true; | |
} | |
} | |
private Transaction createTransaction() { | |
screenToll.displayMessage("Harap tunggu\n"); | |
Transaction temp = new Pay(accID, screenToll, databaseToll); | |
return temp; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package etsToll; | |
public abstract class Transaction { | |
int eTollID; | |
private ScreenToll screenToll; | |
private DatabaseToll databaseToll; | |
public Transaction(int eTollID, ScreenToll screenToll, DatabaseToll databaseToll) { | |
this.eTollID = eTollID; | |
this.screenToll = screenToll; | |
this.databaseToll = databaseToll; | |
} | |
public int geteTollID() { | |
return eTollID; | |
} | |
public ScreenToll getScreen() { | |
return screenToll; | |
} | |
public DatabaseToll getTollDatabase() { | |
return databaseToll; | |
} | |
abstract public void execute(); | |
} |
Output
PBO - ETS - e-Toll Study Case
Reviewed by Ganendra
on
21.30
Rating:

Tidak ada komentar