Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class2: Pizza
- import java.awt.*;
- import java.awt.Color;
- /**
- * Class to represent a single pizza.
- * @author yourStudentNumber
- */
- public class Pizza
- {
- private Canvas canvas;
- private double topLeftX;
- private double topLeftY;
- private String Sauce;
- private String aTopping1;
- private String aTopping2;
- private String aSauce;
- private String aCrust;
- private int aNumberToppings;
- /**
- * Constructor for pizza.
- * @param win the window to draw the pizza on
- * @param startX the top-left x coordinate for the section of screen to draw pizza on
- * @param startY the top-left y coordinate for the section of screen to draw pizza on
- */
- public Pizza(Canvas win, double startX, double startY, String Topping1, String Topping2,String Sauce, int numberToppings, String Crust)
- {
- canvas = win;
- topLeftX = startX;
- topLeftY = startY;
- aTopping1 = Topping1;
- aTopping2 = Topping2;
- aSauce = Sauce;
- aCrust = Crust;
- aNumberToppings = numberToppings;
- }
- /**
- * Method to display the pizza information on the screen.
- */
- public void displayPizza()
- {
- drawPizza();
- drawTopLine();
- drawBottomLine();
- drawSauce();
- if (aTopping1.equals ("Mushroom")){
- drawMushroom1();
- }
- if (aTopping1.equals("Peperoni")){
- drawPeperoni1();
- }
- if(aNumberToppings==2){
- if (aTopping2.equals("Mushroom")){
- drawMushroom2();
- }
- if (aTopping2.equals("Peperoni")){
- drawPeperoni2();
- }
- }
- }
- /**
- * Drawing muchrooms on pizza method
- */
- public void drawMushroom1()
- {
- canvas.setForegroundColor(Color.black);
- canvas.fillSemiCircle(140, 130, 30, 30,false, true);
- canvas.fillSemiCircle(180, 170, 30, 30,false, true);
- canvas.fillSemiCircle(180, 90, 30, 30,false, true);
- canvas.fillSemiCircle(100, 90, 30, 30,false, true);
- canvas.fillSemiCircle(100, 170, 30, 30,false, true);
- canvas.fillRectangle(150, 140, 10, 20);
- canvas.fillRectangle(110, 100, 10, 20);
- canvas.fillRectangle(190, 180, 10, 20);
- canvas.fillRectangle(190, 100, 10, 20);
- canvas.fillRectangle(110, 180, 10, 20);
- }
- public void drawMushroom2()
- {
- canvas.setForegroundColor(Color.black);
- canvas.fillSemiCircle(180, 130, 30, 30,false, true);
- canvas.fillSemiCircle(100, 130, 30, 30,false, true);
- canvas.fillSemiCircle(140, 90, 30, 30,false, true);
- canvas.fillSemiCircle(140, 170, 30, 30,false, true);
- canvas.fillRectangle(190, 140, 10, 20);
- canvas.fillRectangle(110, 140, 10, 20);
- canvas.fillRectangle(150, 100, 10, 20);
- canvas.fillRectangle(150, 180, 10, 20);
- }
- /**
- * Drawing the pepporini as the first topping
- */
- private void drawPeperoni1()
- {
- canvas.setForegroundColor(Color.red);
- canvas.fillCircle(150, 150, 35);
- canvas.fillCircle(190, 110, 35);
- canvas.fillCircle(110, 110, 35);
- canvas.fillCircle(190, 190, 35);
- canvas.fillCircle(110, 190, 35);
- }
- /**
- * Drawing the pepporini as the second topping
- */
- private void drawPeperoni2()
- {
- canvas.setForegroundColor(Color.red);
- canvas.fillCircle(150, 200, 35);
- canvas.fillCircle(150, 100, 35);
- canvas.fillCircle(200, 150, 35);
- canvas.fillCircle(100, 150, 35);
- }
- /**
- * Method to display the pizza on the screen.
- */
- private void drawPizza()
- {
- canvas.setForegroundColor(Color.YELLOW);
- canvas.fillCircle(topLeftX + 150, topLeftY + 150, 200);
- }
- /**
- * Method to draw the sauce
- */
- private void drawSauce()
- {
- if (aSauce.equals("BBQ")){
- canvas.setForegroundColor(Color.orange);
- canvas.fillCircle(topLeftX + 150, topLeftY + 150, 170);
- canvas.setForegroundColor(Color.WHITE);
- canvas.fillCircle(topLeftX + 150, topLeftY + 150, 150);
- }
- else {
- canvas.setForegroundColor(Color.RED);
- canvas.fillCircle(topLeftX + 150, topLeftY + 150, 170);
- canvas.setForegroundColor(Color.WHITE);
- canvas.fillCircle(topLeftX + 150, topLeftY + 150, 150);
- }
- }
- /**
- * Method to write the information shown in the bottom line of the
- * individual pizza on the screen.
- * This method will display the pizza number and size at the top of the
- * screen (once completed)
- */
- private void drawTopLine()
- {
- String topLine = "Pizza";
- double stringX = topLeftX+10;
- double stringY = topLeftY + 25;
- canvas.setForegroundColor(Color.BLACK);
- canvas.setFontSize(15);
- canvas.drawString(topLine, stringX, stringY);
- }
- /**
- * Method to write the information shown in the bottom line of the
- * individual pizza on the screen.
- * This method will display the type of crust and sauce ordered (once
- * completed)
- */
- private void drawBottomLine()
- {
- String bottomLine = "Crust: " + aCrust;
- double stringX = topLeftX+10;
- double stringY = topLeftY + 290;
- canvas.setForegroundColor(Color.BLACK);
- canvas.setFontSize(15);
- canvas.drawString(bottomLine, stringX, stringY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement