Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. Complete Program:
  2.  
  3. // File: Restaurant.java
  4. public class Restaurant
  5. {
  6. private final double SOUP = 2.50;
  7. private final double WINGS = 0.15;
  8. private final double BURGER = 4.95;
  9. private final double CHICKENSANDWICH = 5.95;
  10. private final double FRIES = 1.99;
  11. private final double PIE = 2.95;
  12. private final double ICECREAM = 2.99;
  13. private final double SOFTDRINK = 1.50;
  14. private final double COFFEE = 1.00;
  15. private final double DISCOUNT = 0.25;
  16. private final double TAX = 0.05;
  17.  
  18. private int age;
  19. private int soup;
  20. private int wings;
  21. private int burger;
  22. private int chickensandwich;
  23. private int fries;
  24. private int pie;
  25. private int icecream;
  26. private int softdrink;
  27. private int cofee;
  28.  
  29. private double totalbill;
  30.  
  31. public Restaurant()
  32. {
  33. this.age = 0;
  34. this.soup = 0;
  35. this.wings = 0;
  36. this.burger = 0;
  37. this.chickensandwich = 0;
  38. this.fries = 0;
  39. this.pie = 0;
  40. this.icecream = 0;
  41. this.softdrink = 0;
  42. this.cofee = 0;
  43.  
  44. this.totalbill = 0.0;
  45. }
  46.  
  47. public Restaurant(int age, int soup, int wings, int burger, int chickensandwich, int fries, int pie, int icecream, int softdrink, int cofee)
  48. {
  49. this.age = age;
  50. this.soup = soup;
  51. this.wings = wings;
  52. this.burger = burger;
  53. this.chickensandwich = chickensandwich;
  54. this.fries = fries;
  55. this.pie = pie;
  56. this.icecream = icecream;
  57. this.softdrink = softdrink;
  58. this.cofee = cofee;
  59. calculateTotalbill();
  60. }
  61.  
  62. private void calculateTotalbill()
  63. {
  64. if(age <= 12)
  65. totalbill = 0;
  66. else
  67. totalbill = soup * SOUP + wings * WINGS + burger * BURGER + chickensandwich * CHICKENSANDWICH
  68. + fries * FRIES + pie * PIE + icecream * ICECREAM + softdrink * SOFTDRINK + cofee * COFFEE;
  69.  
  70. if((age >= 13 && age >= 18) || age >= 65)
  71. totalbill = totalbill - totalbill * DISCOUNT;
  72.  
  73. if(age <= 12 || (age > 18 && age < 65))
  74. totalbill = totalbill + totalbill * TAX;
  75. }
  76.  
  77. public double getTotalbill()
  78. {
  79. return totalbill;
  80. }
  81.  
  82. public int getAge()
  83. {
  84. return age;
  85. }
  86. }
  87.  
  88. // File: RestaurantBill.java
  89. import java.util.*;
  90. public class RestaurantBill
  91. {
  92. public static void main(String[] args)
  93. {
  94. Scanner input = new Scanner(System.in);
  95. int n;
  96. int age;
  97. int soup;
  98. int wings;
  99. int burger;
  100. int chickensandwich;
  101. int fries;
  102. int pie;
  103. int icecream;
  104. int softdrink;
  105. int cofee;
  106. int count;
  107. int more = 0;
  108.  
  109. do
  110. {
  111. System.out.print("Number of persons: ");
  112. n = input.nextInt();
  113.  
  114. Restaurant[] orders = new Restaurant[n];
  115.  
  116. System.out.println("Every person who eats at this restaurant orders exactly three items. Never greater, never fewer.");
  117.  
  118. for(int i = 0; i < n; i++)
  119. {
  120. soup = 0;
  121. wings = 0;
  122. burger = 0;
  123. chickensandwich = 0;
  124. fries = 0;
  125. pie = 0;
  126. icecream = 0;
  127. softdrink = 0;
  128. cofee = 0;
  129. count = 0;
  130. System.out.println("Enter order for person " + (i + 1) + ":");
  131.  
  132. System.out.print("Age: ");
  133. age = input.nextInt();
  134.  
  135. System.out.print("Soup: ");
  136. soup = input.nextInt();
  137.  
  138. if(soup > 0)
  139. count++;
  140.  
  141. System.out.print("Wings: ");
  142. wings = input.nextInt();
  143.  
  144. if(wings > 0)
  145. count++;
  146.  
  147. System.out.print("Burger: ");
  148. burger = input.nextInt();
  149.  
  150. if(wings > 0)
  151. count++;
  152.  
  153. if(count == 3)
  154. {
  155. System.out.println("You ordered three items. Thank you.");
  156. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  157. }
  158. else
  159. {
  160. System.out.print("Chickensandwich: ");
  161. chickensandwich = input.nextInt();
  162.  
  163. if(chickensandwich > 0)
  164. count++;
  165.  
  166. if(count == 3)
  167. {
  168. System.out.println("You ordered three items. Thank you.");
  169. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  170. }
  171. else
  172. {
  173. System.out.print("Fries: ");
  174. fries = input.nextInt();
  175.  
  176. if(fries > 0)
  177. count++;
  178.  
  179. if(count == 3)
  180. {
  181. System.out.println("You ordered three items. Thank you.");
  182. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  183. }
  184. else
  185. {
  186. System.out.print("Pie: ");
  187. pie = input.nextInt();
  188.  
  189. if(pie > 0)
  190. count++;
  191.  
  192. if(count == 3)
  193. {
  194. System.out.println("You ordered three items. Thank you.");
  195. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  196. }
  197. else
  198. {
  199. System.out.print("Icecream: ");
  200. icecream = input.nextInt();
  201.  
  202. if(icecream > 0)
  203. count++;
  204.  
  205. if(count == 3)
  206. {
  207. System.out.println("You ordered three items. Thank you.");
  208. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  209. }
  210. else
  211. {
  212. System.out.print("Softdrink: ");
  213. softdrink = input.nextInt();
  214.  
  215. if(softdrink > 0)
  216. count++;
  217.  
  218. if(count == 3)
  219. {
  220. System.out.println("You ordered three items. Thank you.");
  221. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  222. }
  223. else
  224. {
  225. System.out.print("Cofee: ");
  226. cofee = input.nextInt();
  227.  
  228. if(cofee > 0)
  229. count++;
  230.  
  231. if(count == 3)
  232. {
  233. System.out.println("You ordered three items. Thank you.");
  234. orders[i] = new Restaurant(age, soup, wings, burger, chickensandwich, fries, pie, icecream, softdrink, cofee);
  235. }
  236. else
  237. {
  238. System.out.println("You ordered less than three items. Give the order again.");
  239. i--;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248.  
  249. System.out.printf("\n%-10s%4d%10.2f\n", "PERSON#", "AGE", "TOTALBILL");
  250. double grandTotal = 0;
  251. for(int i = 0; i < n; i++)
  252. {
  253. System.out.printf("%-10d%4d%10.2f\n", (i + 1), orders[i].getAge(), orders[i].getTotalbill());
  254. grandTotal = grandTotal + orders[i].getTotalbill();
  255. }
  256. System.out.printf("Grand tatal = $ %.2f\n" + grandTotal);
  257.  
  258. System.out.print("\nEnter 1 if there is one more family wants to give order: ");
  259. more = input.nextInt();
  260. System.out.println();
  261. }while(more == 1);
  262. }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement