Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. class2: Pizza
  2.  
  3. import java.awt.*;
  4. import java.awt.Color;
  5.  
  6. /**
  7. * Class to represent a single pizza.
  8. * @author yourStudentNumber
  9. */
  10.  
  11. public class Pizza
  12. {
  13. private Canvas canvas;
  14. private double topLeftX;
  15. private double topLeftY;
  16. private String Sauce;
  17. private String aTopping1;
  18. private String aTopping2;
  19. private String aSauce;
  20. private String aCrust;
  21. private int aNumberToppings;
  22.  
  23. /**
  24. * Constructor for pizza.
  25. * @param win the window to draw the pizza on
  26. * @param startX the top-left x coordinate for the section of screen to draw pizza on
  27. * @param startY the top-left y coordinate for the section of screen to draw pizza on
  28. */
  29. public Pizza(Canvas win, double startX, double startY, String Topping1, String Topping2,String Sauce, int numberToppings, String Crust)
  30. {
  31. canvas = win;
  32. topLeftX = startX;
  33. topLeftY = startY;
  34. aTopping1 = Topping1;
  35. aTopping2 = Topping2;
  36. aSauce = Sauce;
  37. aCrust = Crust;
  38. aNumberToppings = numberToppings;
  39.  
  40. }
  41.  
  42. /**
  43. * Method to display the pizza information on the screen.
  44. */
  45. public void displayPizza()
  46. {
  47. drawPizza();
  48. drawTopLine();
  49. drawBottomLine();
  50. drawSauce();
  51. if (aTopping1.equals ("Mushroom")){
  52. drawMushroom1();
  53. }
  54. if (aTopping1.equals("Peperoni")){
  55. drawPeperoni1();
  56. }
  57.  
  58. if(aNumberToppings==2){
  59.  
  60. if (aTopping2.equals("Mushroom")){
  61. drawMushroom2();
  62. }
  63. if (aTopping2.equals("Peperoni")){
  64. drawPeperoni2();
  65. }
  66.  
  67. }
  68. }
  69.  
  70. /**
  71. * Drawing muchrooms on pizza method
  72. */
  73. public void drawMushroom1()
  74. {
  75. canvas.setForegroundColor(Color.black);
  76. canvas.fillSemiCircle(140, 130, 30, 30,false, true);
  77. canvas.fillSemiCircle(180, 170, 30, 30,false, true);
  78. canvas.fillSemiCircle(180, 90, 30, 30,false, true);
  79. canvas.fillSemiCircle(100, 90, 30, 30,false, true);
  80. canvas.fillSemiCircle(100, 170, 30, 30,false, true);
  81.  
  82. canvas.fillRectangle(150, 140, 10, 20);
  83. canvas.fillRectangle(110, 100, 10, 20);
  84. canvas.fillRectangle(190, 180, 10, 20);
  85. canvas.fillRectangle(190, 100, 10, 20);
  86. canvas.fillRectangle(110, 180, 10, 20);
  87. }
  88.  
  89. public void drawMushroom2()
  90. {
  91. canvas.setForegroundColor(Color.black);
  92. canvas.fillSemiCircle(180, 130, 30, 30,false, true);
  93. canvas.fillSemiCircle(100, 130, 30, 30,false, true);
  94. canvas.fillSemiCircle(140, 90, 30, 30,false, true);
  95. canvas.fillSemiCircle(140, 170, 30, 30,false, true);
  96.  
  97. canvas.fillRectangle(190, 140, 10, 20);
  98. canvas.fillRectangle(110, 140, 10, 20);
  99. canvas.fillRectangle(150, 100, 10, 20);
  100. canvas.fillRectangle(150, 180, 10, 20);
  101. }
  102.  
  103. /**
  104. * Drawing the pepporini as the first topping
  105. */
  106. private void drawPeperoni1()
  107. {
  108. canvas.setForegroundColor(Color.red);
  109. canvas.fillCircle(150, 150, 35);
  110. canvas.fillCircle(190, 110, 35);
  111. canvas.fillCircle(110, 110, 35);
  112. canvas.fillCircle(190, 190, 35);
  113. canvas.fillCircle(110, 190, 35);
  114.  
  115. }
  116.  
  117. /**
  118. * Drawing the pepporini as the second topping
  119. */
  120. private void drawPeperoni2()
  121. {
  122. canvas.setForegroundColor(Color.red);
  123. canvas.fillCircle(150, 200, 35);
  124. canvas.fillCircle(150, 100, 35);
  125. canvas.fillCircle(200, 150, 35);
  126. canvas.fillCircle(100, 150, 35);
  127. }
  128.  
  129. /**
  130. * Method to display the pizza on the screen.
  131. */
  132. private void drawPizza()
  133. {
  134. canvas.setForegroundColor(Color.YELLOW);
  135. canvas.fillCircle(topLeftX + 150, topLeftY + 150, 200);
  136. }
  137.  
  138. /**
  139. * Method to draw the sauce
  140. */
  141. private void drawSauce()
  142. {
  143. if (aSauce.equals("BBQ")){
  144. canvas.setForegroundColor(Color.orange);
  145. canvas.fillCircle(topLeftX + 150, topLeftY + 150, 170);
  146. canvas.setForegroundColor(Color.WHITE);
  147. canvas.fillCircle(topLeftX + 150, topLeftY + 150, 150);
  148. }
  149. else {
  150. canvas.setForegroundColor(Color.RED);
  151. canvas.fillCircle(topLeftX + 150, topLeftY + 150, 170);
  152. canvas.setForegroundColor(Color.WHITE);
  153. canvas.fillCircle(topLeftX + 150, topLeftY + 150, 150);
  154. }
  155. }
  156.  
  157. /**
  158. * Method to write the information shown in the bottom line of the
  159. * individual pizza on the screen.
  160. * This method will display the pizza number and size at the top of the
  161. * screen (once completed)
  162. */
  163. private void drawTopLine()
  164. {
  165. String topLine = "Pizza";
  166.  
  167. double stringX = topLeftX+10;
  168. double stringY = topLeftY + 25;
  169.  
  170. canvas.setForegroundColor(Color.BLACK);
  171. canvas.setFontSize(15);
  172. canvas.drawString(topLine, stringX, stringY);
  173. }
  174.  
  175. /**
  176. * Method to write the information shown in the bottom line of the
  177. * individual pizza on the screen.
  178. * This method will display the type of crust and sauce ordered (once
  179. * completed)
  180. */
  181. private void drawBottomLine()
  182. {
  183. String bottomLine = "Crust: " + aCrust;
  184.  
  185. double stringX = topLeftX+10;
  186. double stringY = topLeftY + 290;
  187.  
  188. canvas.setForegroundColor(Color.BLACK);
  189. canvas.setFontSize(15);
  190. canvas.drawString(bottomLine, stringX, stringY);
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement