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

The following class Pizza has incomplete codes. Complete the missing lines of co

ID: 3846939 • Letter: T

Question

The following class Pizza has incomplete codes. Complete the missing lines of code for the given parameterized constructor, isLargePizza () method and toString() method. Java Object Orientated Programming

Note: When the diameter of a pizza is more than 20cms, then it is considered to be a Large Pizza.

Hint: The method isLargePizza () has to return a boolean value indicating whether the Pizza object is a large pizza or not.

public class Pizza

{

private String name; private double diameter; // diameter in cms

public Pizza ( String pName, double pDiameter)

{

                        //Missing lines of code have to be completed

}

public boolean isLargePizza()

{

                         //Missing lines of code have to be completed

}

@Override

public String toString()

{

                        //Missing lines of code have to be completed

}

}//end class definition

         

Explanation / Answer

Please find the code snippet :

package com.stm.test;

import java.util.Scanner;

public class Pizza {
private String name; // name of the pizza
private double diameter; // diameter in cms


public Pizza ( String pName, double pDiameter) {
   this.name = pName;
   this.diameter = pDiameter;
}


public boolean isLargePizza() {
   if(diameter>20) {
       return true;
   }
   return false;
}

public static void main(String args[]) {
   Scanner sc = new Scanner(System.in);
   System.out.println("Enter the name of pizza: " );
   String pName = sc.next();
   System.out.println("Enter the diameter of the pizza: ");
   double pDiameter = sc.nextDouble();
  
   Pizza pizza = new Pizza(pName, pDiameter);
  
   boolean isLargePizza = pizza.isLargePizza();
  
   if(isLargePizza) {
       System.out.println("This " + pizza.name +" pizza is large.");
   }
   else {
       System.out.println("This " + pizza.name +" pizza is small.");
   }
  
   sc.close();
}


@Override
public String toString() {

  
return "";

}

}

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