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

Create a class named Pizza. This class should have three fields : a String for t

ID: 3581759 • Letter: C

Question

Create a class named Pizza. This class should have three fields : a String for topping ( such as pepperoni, e.g.) , an integer for diameter in inches ( such as 12, e.g.), and a double for price (e.g., 13.99). Code the proper accessor and mutator methods (i.e. getter and setter for each field variable) to access fields and assign values to all fields. A Pizza class should have also the overloaded constructor which accepts three parameters (topping, diameter and price), and assigns the values passed via these parameters to the Pizza class fields. Save the class as Pizza .java.
Write a class named TestPizza (a driver class) with the main method. This class instantiates a myPizza object form the Pizza class and assigns specific values of topping , diameter and price. These values should be taken as a user’s input making use of JOptionPane or Scanner classes. When the data is assigned to myPizza object fields,   display all the values associated with myPizza object of the Pizza class. Provide   proper label for each property (e.g., “My Pizza topping is: pepperoni” etc).

Note: Pizza class must not have the main method and cannot be run independently. It should be used in driver class to instantiate Pizza objects.

Explanation / Answer

Here goes the required code for both Pizza and PizzaTest classes.

Code:

class Pizza{
   private String topping;
   private int diameter;
   private double price;
   public String getTopping(){
       return topping;
   }
   public int getDiameter(){
       return diameter;
   }
   public double getPrice(){
       return price;
   }
   public void setTopping(String newTopping){
       topping=newTopping;
   }
   public void setDiameter(int newDiameter){
       diameter=newDiameter;
   }
   public void setPrice(double newPrice){
       price=newPrice;
   }
   public Pizza(String newTopping, int newDiameter, double Price){
       this.topping=newTopping;
       this.diameter=newDiameter;
       this.price=newPrice;
   }
  
}

class Testpizza{
   public static void main(String args[]){
       Scanner s=new Scanner(System.in);
       String topping=s.nextLine();
       int diameter=s.nextInt();
       double price=s.nextDouble();
       Pizza myPizza=new Pizza(topping, diameter, price);
      
       System.out.println("My Pizza topping is"+myPizza.getTopping());
       System.out.println("My Pizza diameter is"+ myPizza.getDiameter());
       System.out.println("My Pizza Price is"+myPizza.getPrice());
   }
}

Explanation:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote