Need help writing a set for my pizza code

Here is my current code. I need help getting the list set up to work in pizza and test code.

package pizza;

import java.util.EnumSet;
import java.util.Set;

import pizza.Pizza.Crust;
import pizza.Pizza.Size;
import pizza.Pizza.Topping;

public class Pizza {

// Declare enums
public enum Size{
   SMALL,
   MEDIUM,
   LARGE,
   JUMBO
 }

 public enum Crust{
   CHEESY,
   HAND_TOSSEDS,
   THIN_AND_CRISPY,
   DEEP_PAN
  }

 public enum Topping{
   MUSHROOMS,
   GREEN_PEPPERS,
   HAM,
   PEPPERONI,
   SAUGSAGE
 }

 // declare variables
 private Size pizzaSize;
 private Crust crustType;


 private Set<Topping> setOfToppings = EnumSet.noneOf(Topping.class);
 public Pizza(){


 }
 public void addTopping(Topping topping) {
    setOfToppings.add(topping);
 }

 public Set<Topping> getToppings() {
    return setOfToppings;
 }
 public Pizza(Size pizzaSize, Crust 
  crustType, Topping greenPeppers, Topping saugsage, Topping                
   pepperoni) {
   this.pizzaSize = pizzaSize;
   this.crustType = crustType;


 }

  public Pizza(Size large, Crust cheesy, Topping greenPeppers) {
 // TODO Auto-generated constructor stub
 }
 public Size getPizzaSize() {
   return pizzaSize;
 }
 public void setPizzaSize(Size pizzaSize) {
   this.pizzaSize = pizzaSize;
 }
 public Crust getCrustType() {
   return crustType;
 }
 public void setCrustType(Crust crustType) {
   this.crustType = crustType;
 }

 public String toString(){
   return "A "+pizzaSize+" Pizza with "+ crustType +" crust" + "with " + 
  setOfToppings +      "Toppings";
 }


 }

      

Here is my TestCode

package pizza;

import pizza.Pizza.Crust;
import pizza.Pizza.Size;
import pizza.Pizza.Topping;

public class PizzaTest {

   public static void main(String[] args) {

   // use constructor 1
   Pizza vegieCrunch = new Pizza(); 
   vegieCrunch.setCrustType(Crust.THIN_AND_CRISPY);
   vegieCrunch.setPizzaSize(Size.MEDIUM);
   vegieCrunch.addTopping(Topping.MUSHROOMS);

   // constructor 2
   Pizza doubleCheese = new Pizza(Size.LARGE, Crust.CHEESY, Topping.GREEN_PEPPERS);

   Pizza PartyPizza = new Pizza(Size.JUMBO, Crust.DEEP_PAN, Topping.HAM,
    Topping.SAUGSAGE,   Topping.PEPPERONI);

   // use of getters
   System.out.println("Pizza Vegie Crunch::");
   System.out.println("Size: "+vegieCrunch.getPizzaSize());
   System.out.println("Crust Type: "+vegieCrunch.getCrustType());
   System.out.println("Toppings Chosen: " + vegieCrunch.getToppings());

   // use of toString
   System.out.println("\nPizza Double Cheese:");
   System.out.println(doubleCheese.toString());

   System.out.println("\nPizza Party Pizza:");
   System.out.println(PartyPizza.toString());

 }

}

      

So far it compiles and works fine, but I don't have the option to add or remove fillers for the user. I really need help, thanks everyone!

0


source to share


1 answer


So, you have your topping methods:

public void addTopping(Topping topping) {
    setOfToppings.add(topping);
}

public void removeTopping(Topping topping) {
    setOfToppings.remove(topping);
}

public void addToppings(Topping... toppings) {
    setOfToppings.addAll(Arrays.asList(toppings));
}

public Set<Topping> getToppings() {
    return setOfToppings;
}

      



And this is how you use them in your test code:

// use constructor 1
Pizza vegieCrunch = new Pizza();
vegieCrunch.setCrustType(Crust.THIN_AND_CRISPY);
vegieCrunch.setPizzaSize(Size.MEDIUM);

//////////////////////////////////////////////////////////////
vegieCrunch.addTopping(Topping.MUSHROOMS);
vegieCrunch.addTopping(Topping.HAM);
vegieCrunch.addToppings(Topping.GREEN_PEPPERS, Topping.PEPPERONI);
vegieCrunch.removeTopping(Topping.HAM);
//////////////////////////////////////////////////////////////

      

0


source







All Articles