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

need help writing this java program 2, create a elass named Pizza that steres in

ID: 3777293 • Letter: N

Question


need help writing this java program

2, create a elass named Pizza that steres information about pizza. It shoold costain the size of piza (either Private in variable to store the the toppings, the small, or large, the number of cheese number of pepperoni toppings, aud the number Doppings all of the instance variables. Construc that set he instance variables. Public methods to get a ealsCostl) returns a double that A public method named )that is the cost of the pizza. Pizza cost is determined by: small: S10+S2 r topping Medium: s12 e s2 Per topping Large: SI4 S2 per topping. A public method getDescription() hat returns a String containing the pizza size, quantity of each topping, and the pizza cost as calculated by calsCas write test code to create several pizzas and output their descriptions. For example, a large pizza nith one cheese, one pepperoni and two ham toppings should cost a total of s22.

Explanation / Answer

/* Code Output:
Pizza of large size with 1 cheese toppings, 2 ham toppings and 1 pepperoni toppings will cost $22.0
Pizza of small size with 1 cheese toppings, 2 ham toppings and 1 pepperoni toppings will cost $18.0
Pizza of medium size with 1 cheese toppings, 2 ham toppings and 1 pepperoni toppings will cost $20.0
*/

package abc;

public class RE{
  
   public static void main(String[] args) {
      
       Pizza p = new Pizza("large",1,1,2);
       System.out.println(p.getDescription());
      
       Pizza p1 = new Pizza("small",1,1,2);
       System.out.println(p1.getDescription());
      
       Pizza p2 = new Pizza("medium",1,1,2);
       System.out.println(p2.getDescription());
   }
  
}


class Pizza{

   private String size;
   private int no_of_cheese_toppings;
   private int no_of_pepperoni_toppings;
   private int no_of_ham_toppings;
  
   Pizza(String size, int no_of_cheese_toppings, int no_of_pepperoni_toppings, int no_of_ham_toppings){
      
       this.size = size;
       this.no_of_cheese_toppings = no_of_cheese_toppings;
       this.no_of_pepperoni_toppings = no_of_pepperoni_toppings;
       this.no_of_ham_toppings = no_of_ham_toppings;
   }
  
   public String getSize() {
       return size;
   }

   public void setSize(String size) {
       this.size = size;
   }

   public int getNo_of_cheese_toppings() {
       return no_of_cheese_toppings;
   }

   public void setNo_of_cheese_toppings(int no_of_cheese_toppings) {
       this.no_of_cheese_toppings = no_of_cheese_toppings;
   }
   public int getNo_of_pepperoni_toppings() {
       return no_of_pepperoni_toppings;
   }

   public void setNo_of_pepperoni_toppings(int no_of_pepperoni_toppings) {
       this.no_of_pepperoni_toppings = no_of_pepperoni_toppings;
   }

   public int getNo_of_ham_toppings() {
       return no_of_ham_toppings;
   }

   public void setNo_of_ham_toppings(int no_of_ham_toppings) {
       this.no_of_ham_toppings = no_of_ham_toppings;
   }

   public double calcCost(){
      
       int cost = 0;
      
       if(size.equalsIgnoreCase("Small")){
           cost = 10 + (2*no_of_cheese_toppings) + (2*no_of_ham_toppings) + (2*no_of_pepperoni_toppings);
       }
       else if(size.equalsIgnoreCase("Medium")){
          
           cost = 12 + (2*no_of_cheese_toppings) + (2*no_of_ham_toppings) + (2*no_of_pepperoni_toppings);
       }
       else if(size.equalsIgnoreCase("Large")){
           cost = 14 + (2*no_of_cheese_toppings) + (2*no_of_ham_toppings) + (2*no_of_pepperoni_toppings);
                              
       }
      
       return cost;
   }
  
   public String getDescription(){
      
       double cost = calcCost();
       String str = "Pizza of "+size+" size with "+no_of_cheese_toppings+" cheese toppings, "+no_of_ham_toppings+" ham toppings and "+no_of_pepperoni_toppings+" pepperoni toppings will cost $"+cost;
       return str;
   }
  
}