Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help!! Java Program Please do not use codes already written new code need

ID: 3553858 • Letter: P

Question

Please Help!! Java Program




Please do not use codes already written new code need please do not copy paste thanks!

Create a class named Pizza that stores information about a single Pizza. It should contain the following: Private instance variables to store the size of the Pizza (either small, medium, or large), the number of cheese toppings, the number of pepperoni toppings, and the number of ham toppings. Constructor that set all of the instance variables. Public methods to get and set the instance variables. A public method named calcost() that returns a double that is the cost of the pizza. Pizza cost is determined by: Small: $10+$2 per topping Medium: $12+$2 per topping Large: $14+$2 per topping A public method named getDescription() that returns a String containing the pizza size, quantity of each topping, and the pizza cost as calculated by calCost(). Write test code to create several pizzas and output their descriptions. For example, a large pizza with 1 cheese. 1 pepperoni. and 2 ham toppings should cost a total of $22.

Explanation / Answer

import java.util.*;

class Main
{
private String size;
private int no_of_cheese_toppings;
private int no_of_pepperoni_toppings;
private int no_of_ham_toppings;
public Main()
{
size = "Small";
no_of_cheese_toppings = 0;
no_of_pepperoni_toppings = 0;
no_of_ham_toppings = 0;
}
public void set_size(String str)
{
size = str;
}
public void set_no_of_cheese_toppings(int k)
{
no_of_cheese_toppings = k;
}
public void set_no_of_pepperoni_toppings(int k)
{
no_of_pepperoni_toppings = k;
}
public void set_no_of_ham_toppings(int k)
{
no_of_ham_toppings =k;
}
public String get_size()
{
return size;
}
public int get_no_of_cheese_toppings()
{
return no_of_cheese_toppings;
}
public int get_no_of_pepperoni_toppings()
{
return no_of_pepperoni_toppings;
}
public int get_no_of_ham_toppings()
{
return no_of_ham_toppings;
}
public double calcCost()
{
double cost = 0;
int k = get_no_of_cheese_toppings() + get_no_of_pepperoni_toppings() + get_no_of_ham_toppings();
if(size.equalsIgnoreCase("small"))
{
cost = 10 + 2*k;
}
else if(size.equalsIgnoreCase("medium"))
{
cost = 12 + 2*k;
}
if(size.equalsIgnoreCase("large"))
{
cost = 14 + 2*k;
}
return cost;
}

public void getDescription( )
{
System.out.println(" Main size is " + size + " number of cheese toppings " + get_no_of_cheese_toppings() +
" number of pepperoni toppings " + get_no_of_pepperoni_toppings() + " number of ham toppings " + get_no_of_ham_toppings());
System.out.println(" cost of this pizza is " + calcCost());
}

public static void main(String[] args)
{
Main a = new Main();
a.set_size("large");
a.set_no_of_cheese_toppings(1);
a.set_no_of_pepperoni_toppings(1);
a.set_no_of_ham_toppings(2);
a.getDescription( );
System.out.println(" ");
Main b = new Main();
b.set_size("small");
b.set_no_of_cheese_toppings(1);
b.getDescription( );


}

}