Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pepperoni P 0.99 Sausage S 0.99 Onions O 0.79 GreenPeppers G 0.69 Mushrooms M 0.79 Ham H 0.89 Pineapple A 0.89 Pizza The pizza class

  • Pepperoni P 0.99
  • Sausage S 0.99
  • Onions O 0.79
  • GreenPeppers G 0.69
  • Mushrooms M 0.79
  • Ham H 0.89
  • Pineapple A 0.89

Pizza

The pizza class also extends DecoratedPizza, but it has only the Crust as an instance variable, so the Pizza class will call the default constructor in its parent class (DecoratedPizza). The Pizza class represents the "base" pizza (with no toppings). The pizzaCost and toString methods will use the Crust instance variable, and the getImage methodappendsan S, M, or L to the String representing the image file(We are not going to get an image file). The size of the pizza will then be the first letter added to the image file String. The final image file name will look like MPOS.jpg for a medium pizza with pepperoni, onions, and sausage. This means that the pepperoni topping was selected first, followed by onions and then sausage. The GUI will append the ".jpg" for you.

Pizza Builder

There is a lot of input validation that must be done in this program(Input are done through a text file). You will use theBuilder design patternto handle input validation. The Builder design pattern places all of the input validation in a separate class, making the core classes much more readable. PizzaBuilder will need to keep track of some information as instance variables. One of these is thetop linkin the DecoratedPizza (the head of the linked list). Use as few instance variables as possible (I will count off for bad designs).

Write the following methods in PizzaBuilder:

  • protected void buildPizza()

//Do a Crust and a Pizza using that Crust based on the user's specifications (the Pizza is now ready for toppings)

  • public PizzaBuilder() //start with a small, thin pizza with no toppings as the default
  • public boolean setSize(char try_size) //returns true if the input was valid ("S" or "small", etc., not case sensitive, use the String charAt method to get the first character)
  • public boolean setCrust(String try_crust) //("thin", "hand", or "pan", not case sensitive)
  • public void addTopping(char topping_char) //compare the topping abbreviation to topping_char to determine which topping to add (using void here is convenient for the PizzaDriver, ignore invalid abbreviations)
  • public DecoratedPizza pizzaDone() //return the final DecoratedPizza and reset to the default pizza if another pizza is desired

DecoratedPizza.java

public abstract class DecoratedPizza extends Pizza{

public abstract String getDescription();

}

public abstract class DecoratedPizza {

private DecoratedPizza next_pizza_item;

public DecoratedPizza(){

this.next_pizza_item = null;

}

public DecoratedPizza(DecoratedPizza next_pizza_item){

this.next_pizza_item = next_pizza_item;

}

public abstract double pizzaCost();

public String toString();

public abstract String getImage();

}

CrustEnum.java

public class CrustEnum{

public enum CrustSize{

S(5.99), M(7.99), L(9.99);

private double value;

private CrustSize(double val){

this.value = val;

}

public double cost(){

return this.value;

}

public String getSize(){

return toString();

}

}

public enum CrustType{

THIN(0.00), HAND(0.50), PAN(1.00);

private double value;

private CrustSize(double val){

this.value = val;

}

public double cost(){

return this.value;

}

public String getSize(){

return toString();

}

}

private CrustSize size;

private CrustType type;

public CrustEnum(String cType, String cSize){

this.type = CrustType.valueof(cType)

this.size = CrustSize.valueof(cSize)

}

public double getCost(){

return (this.size.cost() +this.type.cost());

}

public String getCrust(){

return type.getCrust();

}

public String getSize(){

return type.getSize();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions