public class Pizza
{
private String size ;
private int cheeseTops;
private int pepperoniTops;
private int hamTops;
private int price;
public void Pizza(String s, int c, int p, int h) //initilize pizza class with variables
{
size = s;
cheeseTops = c;
pepperoniTops = p;
hamTops = h;
}
public void calcCost() //Gets total price of the pizza
{
int totalTops = getCheeseTops() + getPepperoniTops() + getHamTops();
if(size == "small")
{
price = 10 + 2 * totalTops;
}
if(size == "medium")
{
price = 12 + 2 * totalTops;
}
if(size == "large")
{
price = 14 + 2 * totalTops;
}
}
public void display() //Displays size, toppings and total price of the pizza
{
System.out.println("Pizza Size: " + getSize());
System.out.println("Toppings: " + getCheeseTops() + " cheese, " + getPepperoniTops() + " pepperoni, "
+ getHamTops() + " ham");
System.out.println("Total cost: $" + getPrice());
}
public void setSize(String s) //Set size of pizza class
{
size = s;
}
public void setCheeseTops(int c) //Set amount of cheese toppings
{
cheeseTops = c;
}
public void setPepperoniTops(int p) //Set amount of pepperoni toppings
{
pepperoniTops = p;
}
public void setHamTops(int h) //Set amount of ham toppings
{
hamTops = h;
}
public double getPrice() //Dispalys total price of pizzza
{
return(price);
}
public String getSize() //Displays size of pizza
{
return(size);
}
public int getCheeseTops() //Displays amount of cheese toppings
{
return(cheeseTops);
}
public int getPepperoniTops() //Displays amount of pepperoni toppings
{
return(pepperoniTops);
}
public int getHamTops() //Displays amount ham toppings
{
return(hamTops);
}
}
public class PizzaOrderDriver
{
public static void main (String[] args)
{
Pizza p1 = new Pizza("small", 1, 0, 1); // cost=10+2+2=14
Pizza p2 = new Pizza("medium", 1, 1, 1); // cost = 12+2+2+2=18
Pizza p3 = new Pizza("large", 1, 1, 2); // cost = 14+2+2+4 = 22
// create one PizzaOrder object
PizzaOrder po1 = new PizzaOrder(3, p1, p2, p3);
System.out.println("Pizza Order #1:");
po1.displayOrder(); // total cost = 14+ 18+22 = 54
// create another PizzaOrder object with copy constructor
PizzaOrder po2 = new PizzaOrder(po1);
po2.getPizza1().setCheeseToppings(3); // p1 cost=10+6+0+2=18
System.out.println("Pizza Order #2:");
po2.displayOrder(); // total cost = 18 + 18 + 22 = 58
}
}
For some reason the Pizza constructor won't work. It keeps telling me it doesn't need variables. I really don't understand why either. If anyone could help me I would really appreciate it.