/**
* Ini adalah program Ticket Machine yang bisa menampilkan harga tiket,
* sisa saldo, dan tampilan print ticket. apabila uang mencukupi akan ditampilkan
* tampilan tiket apabila kurang mencukupi akan ditampilkan kurangnya berapa
* yang harus ditambahkan
*
* @author Bima S. Ramadhan
* @version 1.0
*/
public class TicketMachine
{
private int price; private int balance; private int total;
public TicketMachine(int ticketCost)
{
price=ticketCost; balance = 0; total=0;
}
public int getPrice()
{
return price;
}
public int getBalance()
{
return balance;
}
public void insertMoney(int amount)
{
balance=balance+amount;
}
public void printTicket()
{
if(balance>=price){
System.out.println("================================");
System.out.println("SELAMAT DATANG DI BLUEJ AIRLINES");
System.out.println(" HARGA TIKET ");
System.out.println(" Rp" + price +",-");
System.out.println("================================");
System.out.println();
balance = balance-price;
}
else{
System.out.println("===================================");
System.out.println("Maaf Uang yang anda masukkan kurang");
System.out.println("Mohon masukkan Rp"+ (price-balance)+",-");
System.out.println("===================================");
}
}
}
/**
* Ini adalah program Ticket Machine yang bisa menampilkan harga tiket,
* sisa saldo, dan tampilan print ticket. apabila uang mencukupi akan ditampilkan
* tampilan tiket apabila kurang mencukupi akan ditampilkan kurangnya berapa
* yang harus ditambahkan
*
* @author Bima S. Ramadhan
* @version 1.0
*/
import java.util.Scanner;
public class mainTicket
{
public static int main()
{
Scanner scan = new Scanner(System.in);
int cost,menu;
System.out.println("Masukkan harga tiket: ");
cost=scan.nextInt();
TicketMachine ticket= new TicketMachine(cost);
while(true)
{
System.out.println("1. Get Price");
System.out.println("2. Get Balance");
System.out.println("3. Insert Money");
System.out.println("4. Print Ticket");
System.out.println("5. Exit");
menu=scan.nextInt();
switch(menu)
{
case 1:
System.out.println("Harga tiket : Rp"+ticket.getPrice()+",-");
break;
case 2:
System.out.println("Sisa saldo Anda : Rp"+ticket.getBalance()+",-");
break;
case 3:
int money=scan.nextInt();
ticket.insertMoney(money);
break;
case 4:
ticket.printTicket();
break;
case 5:
return 0;
}
}
}
}
0 comments:
Post a Comment