Ticket Machine
/**
* Ticket Machine
*
* @author (Ismail)
* @version (16092018)
*/
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 += amount;
}
public void printTicket()
{
int bayar = balance;
balance = balance - price;
System.out.println("####################");
System.out.println("# Cinema XVIII");
System.out.println("# Tiket");
System.out.println("# " + price + " Rupiah");
System.out.println("Bayar "+bayar+" Rupiah");
System.out.println("Kembalian "+balance+" Rupiah");
System.out.println("####################");
System.out.println();
total = total + balance;
balance = 0;
}
}
Main
/**
* Main
*
* @author (Ismail)
* @version (16092018)
*/
import java.util.Scanner;
public class IntMain
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int cost, menu;
System.out.println("Masukkan harga tiket \n");
cost = scan.nextInt();
TicketMachine ticket = new TicketMachine(cost);
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");
int tipe=1;
while(tipe == 1)
{
menu = scan.nextInt();
switch(menu)
{
case 1:
cost = ticket.getPrice();
System.out.println(cost);
break;
case 2:
System.out.print(ticket.getBalance()+"\n");
break;
case 3:
int money = scan.nextInt();
ticket.insertMoney(money);
break;
case 4:
ticket.printTicket();
break;
case 5:
tipe=0;
break;
}
}
}
}
Tidak ada komentar:
Posting Komentar