Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ticketing {
- static int tickets = 10;
- static double sellPrice = 9.9;
- static double earned = 0;
- static int buyTickets = 0;
- public static void main(String[] args) {
- int menuId = 0;
- do {
- printMenu();
- System.out.print("Enter Menu Function: ");
- menuId = Input.readInt();
- switch (menuId) {
- case 1:
- sellTickets();
- break;
- case 2:
- ticketsLeft();
- break;
- case 3:
- cashReister();
- break;
- case 0:
- endingProcess();
- break;
- default:
- System.out.println("Unknown Menu Function");
- break;
- }
- } while (menuId != 0);
- }
- private static void sellTickets() {
- if (tickets <= 0) {
- System.out.println("No tickets left for sale");
- return;
- } else
- do {
- System.out.println("Enter amount of tickets to be bought: ");
- buyTickets = Input.readInt();
- if (buyTickets > 0) {
- if (tickets - buyTickets >= 0) {
- double price = Math.round(sellPrice * buyTickets * 100) / 100d;
- earned += price;
- System.out.printf("Sell Price: %.2f\n", price);
- tickets -= buyTickets;
- return;
- } else {
- System.out.println("Not enough tickets left");
- return;
- }
- }
- } while (buyTickets > 0 && tickets > 0);
- }
- private static void ticketsLeft(){
- System.out.printf("%d Tickets left\n", tickets);
- }
- private static void cashReister(){
- System.out.printf("The Cash Register contains %.2f €\n", Math.round(earned * 100) / 100d);
- }
- private static void endingProcess (){
- System.out.printf("%d Tickets left\n", tickets);
- System.out.printf("The Cash Register contains %.2f €\n", Math.round(earned * 100) / 100d);
- System.out.println("Bye!");
- }
- private static void printMenu() {
- System.out.println("Main Menu: ");
- System.out.println(" 1) Sell Tickets");
- System.out.println(" 2) Show Tickets Left");
- System.out.println(" 3) Show Balance");
- System.out.println(" 0) Exit");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement