Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.48 KB | None | 0 0
  1. Class 1: OrderingSystem
  2.  
  3.  
  4.  
  5.  
  6. import java.awt.*;
  7. import java.util.Scanner;
  8. import java.text.DecimalFormat;
  9.  
  10. /**
  11. * Class to manage the pizza order.
  12. * @author up835351
  13. */
  14. public class OrderingSystem
  15. {
  16. private Canvas canvas;
  17. private double Price;
  18. private String Topping1;
  19. private String Topping2;
  20. private String Sauce;
  21. private String Size;
  22. private String Crust;
  23. private double BaseArea;
  24. private int numberToppings;
  25. private int numberPizza;
  26.  
  27. /**
  28. * Constructor for the ordering system.
  29. */
  30. public OrderingSystem()
  31. {
  32. canvas = new Canvas("Pizza Ordering", 900, 650);
  33. }
  34.  
  35. /**
  36. * Method to draw the outline of the order screen.
  37. */
  38. public void drawOrderScreen()
  39. {
  40. canvas.setForegroundColor(Color.BLACK);
  41. // vertical dividers
  42. canvas.drawLine(300, 0, 300, 600);
  43. canvas.drawLine(600, 0, 600, 600);
  44.  
  45. // halfway divider
  46. canvas.drawLine(0, 300, 900, 300);
  47.  
  48. canvas.drawLine(0, 600, 900, 600);
  49. canvas.setForegroundColor(Color.BLACK);
  50. canvas.setFontSize(25);
  51. DecimalFormat df = new DecimalFormat("#.00");
  52. String StrPrice = df.format(this.getPrice());
  53. canvas.drawString("Total Price of the Order:" + StrPrice, 10, 640);
  54. }
  55.  
  56. // Selecting the Sauce
  57. static String setSauce(){
  58. System.out.print("what Sauce would you like, BBQ or tomato ?: ");
  59. Scanner saucescanner = new Scanner(System.in);
  60. String Sauce = saucescanner.nextLine();
  61.  
  62. if (Sauce.equals("BBQ")){
  63. System.out.print( "BBQ sauce selected ! ");
  64. }
  65. else if (Sauce.equals("Tomato")){
  66. System.out.print( "Tomato selected !" );
  67. }
  68.  
  69. else {
  70. saucescanner.reset();
  71. System.out.print("Invalid Sauce! ");
  72. Sauce = setSauce();
  73.  
  74. }
  75. return Sauce;
  76. }
  77.  
  78. /*
  79. * quantity of toppings
  80. */
  81. public int startToppings()
  82. {
  83. Boolean badNumber = true;
  84. Scanner scanner = new Scanner(System.in);
  85. System.out.print("How many toppings would you like ? 1 or 2 ?: ");
  86. int numberToppings = scanner.nextInt();
  87. while (badNumber){
  88. if(numberToppings >=3 && numberToppings <=0){
  89. System.out.print('\u000C');
  90. System.out.print("invalid number, please try again: ");
  91. scanner.reset();
  92. Scanner tryAgain = new Scanner(System.in);
  93. System.out.print("How many toppings would you like ? 1 or 2 ?: ");
  94. numberToppings = tryAgain.nextInt();
  95. }
  96. else {
  97. System.out.print(numberToppings + "Topping(s) selected ");
  98. badNumber=false;
  99. }
  100. }
  101. return numberToppings;
  102. }
  103.  
  104. public int numberOfPizza(){
  105. Boolean LoopNum = true;
  106. Scanner scanner = new Scanner(System.in);
  107. System.out.print("How many pizza's would you like ( Max. 6): ");
  108. int numberPizza = scanner.nextInt();
  109. while (LoopNum){
  110. if(numberPizza >0 && numberPizza <=6){
  111. System.out.print('\u000C');
  112. System.out.print("invalid number, please try again: ");
  113. scanner.reset();
  114. Scanner tryAgain = new Scanner(System.in);
  115. System.out.print("How many pizza's would you like ( Max. 6): ");
  116. numberPizza = tryAgain.nextInt();
  117. }
  118. else {
  119. System.out.print(numberPizza + "Pizza(s) selected ");
  120. LoopNum=false;
  121. }
  122. }
  123. return numberPizza;
  124. }
  125.  
  126. /*
  127. * choise of toppings
  128. */
  129.  
  130. static String setTopping1()
  131. {
  132. System.out.print("what would you like for your first topping, Mushroom or Peperoni ? ");
  133. Scanner scanner1 = new Scanner(System.in);
  134. String Topping1 = scanner1.nextLine();
  135. if (Topping1.equals("Peperoni")){
  136. System.out.print( "Peperoni selected ! ");
  137. }
  138. else if (Topping1.equals("Mushroom")){
  139. System.out.print( "Mushroom selected ! ");
  140. }
  141. else {
  142. scanner1.reset();
  143. System.out.print("Invalid Topping! ");
  144. Topping1=setTopping1();
  145. }
  146. return Topping1;
  147.  
  148. }
  149.  
  150. static String setTopping2()
  151. {
  152.  
  153. System.out.print("what would you like for your second topping, Mushroom or Peperoni ? ");
  154. Scanner scanner2 = new Scanner(System.in);
  155. String Topping2 = scanner2.nextLine();
  156. if (Topping2.equals("Peperoni")){
  157. System.out.print( "Peperoni selected ! ");
  158. }
  159. else if (Topping2.equals("Mushroom")){
  160. System.out.print( "Mushroom selected !" );
  161. }
  162.  
  163. else {
  164. scanner2.reset();
  165. System.out.print("Invalid Topping! ");
  166. Topping2=setTopping2();
  167. }
  168.  
  169. return Topping2;
  170. }
  171.  
  172. public String setSize(){
  173. System.out.print("What size would you like: Large, Medium or Small? : ");
  174. Scanner sizescanner = new Scanner(System.in);
  175. String Size = sizescanner.nextLine();
  176.  
  177. if (Size.equals("Large")){
  178. System.out.print( "Large selected ! ");
  179. this.Size = Size;
  180. }
  181. else if (Size.equals("Medium")){
  182. System.out.print( "Medium selected !" );
  183. this.Size = Size;
  184. }
  185.  
  186. else if (Size.equals("Small")){
  187. System.out.print( "Small selected !" );
  188. this.Size = Size;
  189. }
  190.  
  191. else {
  192. sizescanner.reset();
  193. System.out.print("Invalid Size! ");
  194. setSize();
  195. }
  196. return Size;
  197.  
  198. }
  199.  
  200. public double baseArea(String Size){
  201. BaseArea=0;
  202. if (Size.equals("Large")){
  203. BaseArea = 153.94;
  204. }
  205. else if (Size.equals("Medium")){
  206. BaseArea = 113.0976;
  207. }
  208.  
  209. else if (Size.equals("Small")){
  210. BaseArea = 78.54;
  211. }
  212. return BaseArea;
  213. }
  214.  
  215. public double getPrice(){
  216. return Price;
  217. }
  218.  
  219. public String Crust(){
  220. System.out.print("What crust would you like: Deep Pan, Thin Crust or Stuffed Crust? : ");
  221. Scanner crustscanner = new Scanner(System.in);
  222. String Crust = crustscanner.nextLine();
  223.  
  224. if (Crust.equals("Deep Pan")){
  225. System.out.print( "Deep Pan selected ! ");
  226. this.Crust = Crust;
  227. }
  228. else if (Crust.equals("Thin Crust")){
  229. System.out.print( "Thin Crust selected !" );
  230. this.Crust = Crust;
  231. }
  232.  
  233. else if (Crust.equals("Stuffed Crust")){
  234. System.out.print( "Stuffed Crust selected !" );
  235. this.Crust = Crust;
  236. }
  237.  
  238. else {
  239. crustscanner.reset();
  240. System.out.print("Invalid crust! ");
  241. Crust();
  242. }
  243.  
  244. return Crust;
  245. }
  246.  
  247. public void calculatePrice(String Topping1, String Topping2, double Price, String Crust, double baseArea, Canvas canvas){
  248. Price = 0;
  249.  
  250. // Topping price
  251.  
  252. if (Topping1.equals("Mushroom")){
  253. Price += (0.05*5);
  254. }
  255. else {
  256. Price += (0.04*5);
  257. }
  258.  
  259. if (numberToppings == 2){
  260. if (Topping2.equals("Mushroom")){
  261. Price += (0.05*4);
  262. }
  263. else {
  264. Price += (0.04*4);
  265. }
  266. }
  267. // Sauce price
  268. if (Sauce.equals("BBQ")){
  269. Price+= 0.50;
  270. }
  271.  
  272. //Crust Price
  273.  
  274. if (Crust.equals("Deep Pan")){
  275. Price += (0.11*baseArea);
  276. }
  277. if (Crust.equals("Thin Crust")){
  278. Price += (0.08*baseArea);
  279. }
  280. if (Crust.equals("Stuffed Crust")){
  281. Price += (0.14*baseArea);
  282. }
  283.  
  284. System.out.print ("current price" + Price);
  285. this.setPrice(Price);
  286.  
  287. }
  288.  
  289. public void setPrice(double newPrice){
  290. this.Price= newPrice;
  291. }
  292.  
  293. /**
  294. * Method to manage the ordering of the pizzas (once completed).
  295. */
  296. public void startOrdering()
  297. {
  298.  
  299.  
  300. Size=this.setSize();
  301. BaseArea = this.baseArea(Size);
  302. Crust= this.Crust();
  303. numberToppings = this.startToppings();
  304. Sauce = this.setSauce();
  305. Topping1 = this.setTopping1();
  306. if (numberToppings==2){
  307. Topping2 = this.setTopping2();
  308. }
  309. calculatePrice(Topping1,Topping2,Price,Crust,BaseArea,canvas);
  310.  
  311. Pizza pizza1 = new Pizza(canvas, 0, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
  312. pizza1.displayPizza();
  313.  
  314. Pizza pizza2 = new Pizza(canvas, 300, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
  315. pizza2.displayPizza();
  316.  
  317. Pizza pizza3 = new Pizza(canvas, 600, 0,Topping1,Topping2, Sauce,numberToppings, Crust);
  318. pizza3.displayPizza();
  319.  
  320. Pizza pizza4 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
  321. pizza4.displayPizza();
  322.  
  323. Pizza pizza5 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
  324. pizza4.displayPizza();
  325.  
  326. Pizza pizza6 = new Pizza(canvas, 0, 300,Topping1,Topping2, Sauce,numberToppings, Crust);
  327. pizza4.displayPizza();
  328.  
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement