Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class Restaruant{
  4. static int budget=100;
  5. static Scanner sc=new Scanner(System.in);
  6. public static int Menu(){
  7. System.out.println("1 - View Item menu");
  8. System.out.println("2 – Pay total due");
  9. System.out.println("3 – Add $5 in credit");
  10. System.out.println("4 – Clear order");
  11. int f=sc.nextInt();
  12. if(f==-1||(f>=1&&f<=4)){
  13. return f;
  14. }else{
  15. System.out.println("Please enter a valid option!");
  16. Menu();
  17. }
  18. return 0;
  19. }
  20. public static double ViewMenu(double total){
  21. int op;
  22. System.out.println("1) Toaster: $19.99\n(2) Coffee maker: $29.49\n(3) Waffle maker: $15.79\n(4) Blender: $24.99\n(5) Kettle: $$24.99\n(6) Go to the main menu");
  23. op=sc.nextInt();
  24. switch(op){
  25. case 6:
  26. System.out.printf("Your current total is: $%.2f\n",total);
  27. return total;
  28. case 1:
  29. System.out.println("You have added a Toaster maker to your order.");
  30. total+=19.99;
  31. break;
  32. case 2:
  33. System.out.println("You have added a Coffee maker to your order.");
  34. total+=29.49;
  35. break;
  36. case 3:
  37. System.out.println("You have added a Waffle maker to your order.");
  38. total+=15.79;
  39. break;
  40. case 4:
  41. System.out.println("You have added a Blender maker to your order.");
  42. total+=24.99;
  43. break;
  44. case 5:
  45. System.out.println("You have added a Kettle maker to your order.");
  46. total+=24.99;
  47. break;
  48. default:
  49. System.out.println("Invalid item number please try again");
  50. }
  51. return ViewMenu(total);
  52. }
  53. public static boolean PayTotalDue(double total){
  54. double temp=total;
  55. if(temp>50){
  56. temp-=temp*0.2;
  57. temp+=temp*0.085;
  58. //System.out.println(temp);
  59. if(temp<=budget){
  60. System.out.printf("Thank you! You saved: $%.2f ",(total+(total*0.085)-temp));
  61. System.out.printf("Your change is: $%.2f\n",(budget-temp));
  62. System.out.println("Your items will be on their way soon!");
  63. }else{
  64. System.out.println("Insufficient funds!");
  65. return false;
  66. }
  67.  
  68. }else{
  69. temp+=temp*0.085;
  70. System.out.printf("Thank you! Your change is: %.2f\n",(budget-temp));
  71. System.out.println("Your items will be on their way soon!");
  72. }
  73. return true;
  74. }
  75. public static void main(String args[]){
  76. double total=0;
  77. int f;
  78. while(true){
  79. f=Menu();
  80. int end=0;
  81. switch(f){
  82. case 1:
  83. total=ViewMenu(total);
  84. break;
  85. case 2:
  86. if(PayTotalDue(total)){
  87. total=0;
  88. end=1;
  89. }
  90. break;
  91. case 3:
  92. budget+=5;
  93. System.out.println("Credit available: $ "+budget);
  94. break;
  95. case 4:
  96. System.out.println("Current order balance has been cleared. Current due: $0.00 ");
  97. total=0;
  98. break;
  99. default:
  100. break;
  101. }
  102. if(end==1){
  103. break;
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement