Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. public class Ticketing {
  2. static int tickets = 10;
  3. static double sellPrice = 9.9;
  4. static double earned = 0;
  5. static int buyTickets = 0;
  6. public static void main(String[] args) {
  7. int menuId = 0;
  8.  
  9. do {
  10. printMenu();
  11. System.out.print("Enter Menu Function: ");
  12. menuId = Input.readInt();
  13. switch (menuId) {
  14. case 1:
  15. sellTickets();
  16. break;
  17. case 2:
  18. ticketsLeft();
  19. break;
  20. case 3:
  21. cashReister();
  22. break;
  23. case 0:
  24. endingProcess();
  25. break;
  26. default:
  27. System.out.println("Unknown Menu Function");
  28. break;
  29. }
  30. } while (menuId != 0);
  31. }
  32. private static void sellTickets() {
  33. if (tickets <= 0) {
  34. System.out.println("No tickets left for sale");
  35. return;
  36. } else
  37. do {
  38. System.out.println("Enter amount of tickets to be bought: ");
  39. buyTickets = Input.readInt();
  40. if (buyTickets > 0) {
  41. if (tickets - buyTickets >= 0) {
  42. double price = Math.round(sellPrice * buyTickets * 100) / 100d;
  43. earned += price;
  44. System.out.printf("Sell Price: %.2f\n", price);
  45. tickets -= buyTickets;
  46. return;
  47. } else {
  48. System.out.println("Not enough tickets left");
  49. return;
  50. }
  51. }
  52. } while (buyTickets > 0 && tickets > 0);
  53. }
  54. private static void ticketsLeft(){
  55. System.out.printf("%d Tickets left\n", tickets);
  56. }
  57. private static void cashReister(){
  58. System.out.printf("The Cash Register contains %.2f €\n", Math.round(earned * 100) / 100d);
  59. }
  60. private static void endingProcess (){
  61. System.out.printf("%d Tickets left\n", tickets);
  62. System.out.printf("The Cash Register contains %.2f €\n", Math.round(earned * 100) / 100d);
  63. System.out.println("Bye!");
  64. }
  65. private static void printMenu() {
  66. System.out.println("Main Menu: ");
  67. System.out.println(" 1) Sell Tickets");
  68. System.out.println(" 2) Show Tickets Left");
  69. System.out.println(" 3) Show Balance");
  70. System.out.println(" 0) Exit");
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement