Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String[]args)
- {
- Scanner sc = new Scanner(System.in);
- int cost, menu;
- boolean exit = false;
- //takes price as input for current ticket machine
- System.out.print("Input the price of the ticket : ");
- cost = sc.nextInt();
- //instantiates a new ticketmachine instance
- TicketMachine tiket = new TicketMachine(cost);
- while(!exit)
- {
- System.out.println("\nTicket Machine Application");
- 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 = sc.nextInt();
- int uang;
- switch(menu)
- {
- //if the user wants to see the ticket price
- //of the current ticket machine
- case 1:
- cost=tiket.getPrice();
- System.out.println("Cost : "+cost);
- break;
- //if the user wants to check the amount of
- //money already inserted into the machine
- case 2:
- System.out.println("Balance : "+tiket.getBalance());
- break;
- //if the user wants to input money into the machine
- case 3:
- System.out.println("Input Money inserted : ");
- uang=sc.nextInt();
- tiket.insertMoney(uang);
- break;
- //if the use wants to buy and print a ticket from
- //the ticket machine
- case 4:
- tiket.printTicket();
- break;
- //when the user wants to exit the ticket machine program
- case 5:
- if(tiket.getBalance() > 0) {
- System.out.println("Giving Change for : " + tiket.getBalance());
- }
- System.out.println("Thank You and Good Bye");
- exit = true;
- break;
- //error handling if the user doesn't pick any of the
- //given options
- default:
- System.out.println("Input Not Defined");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement