Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.11) Create a class named Pizza that stores information about a single pizza. It should contain the following: Private instance variables to store the size

4.11) 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(s) that set all of the instance variables. Public methods to get and set the instance variables. A public method named calcCost( ) 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 calcCost(). Write main method that asks for pizza size and number of toppings for each category. It should then initialize Pizza class and Print out the string from getDescription();

**IT HAS TO FOLLOW THIS RESULT**:

EnterthesizeofPizza:Large

EnterthenumberofCheesetoppings:2

EnterthenumberofPepperonitoppings:0

EnterthenumberofHamtoppings:1

LargePizzawith2Cheesetoppings,0Pepperonitoppings,and1Hamtoppings.

TotalPrice:20.0

THANK YOU IN ADVANCE

**PLEASE DO IT IN JAVA AND IT HAS TO FOLLOW THE DIRECTIONS ABOVE**

I GOT THE ERROR RESULTS:

Given the following was entered from the keyboard: Large 1 1 2 you displayed: instead of: Enter the size of Pizza:Enter the number of Cheese toppings:Enter the number of Pepperoni toppings:Enter the number of Ham toppings:Large Pizza with 1 Cheese toppings, 1 Pepperoni toppings, and 2 Ham toppings. Total Price: 22.0

**MY CODE**:

import java.util.Scanner; //program uses class scanner

class Pizza

{

private String size;

private int cheesetoppings,pepperonitoppings,hamtoppings;

private int price;

public Pizza(String setSize)

{

this.size = setSize;

setToppings();

System.out.println("");

}

public void setSize(String size)

{

this.size = size;

}

public void setToppings()

{

//Create a Scanner to obtain input from the

//command window

Scanner input=new Scanner(System.in);

//input sides of triangle

System.out.print("Enter number of Cheese toppings: ");

this.cheesetoppings=input.nextInt();

System.out.print("Enter number of Pepper toppings: ");

this.pepperonitoppings=input.nextInt();

System.out.print("Enter number of Ham-toppings: ");

this.hamtoppings=input.nextInt();

}

public String getSize()

{

return this.size;

}

public void calculatePrice()

{

if(size.equals("Small"))

this.price=10+2*(hamtoppings+pepperonitoppings+cheesetoppings);

else if(size.equals("Medium"))

this.price=12+2*(hamtoppings+pepperonitoppings+cheesetoppings);

else if(size.equals("Large"))

this.price=14+2*(hamtoppings+pepperonitoppings+cheesetoppings);

}

public String toString()

{

String str=size+" pizza with"+cheesetoppings+" cheese"+pepperonitoppings+" Pepper "+hamtoppings+" Ham Cost: $"+price;

return str;

}

}

class pizzaTest//HypotenuseTest

{

// method main begins execution of Java application

public static void main( String args[] )

{

String size;

//Create a Scanner to obtain input from the

//command window

Scanner input=new Scanner(System.in);

//input sides of triangle

System.out.print("Enter size of Pizza ");

size=input.nextLine();

//instantiate pizza class

Pizza pizza1=new Pizza(size);

pizza1.calculatePrice();

System.out.println(pizza1);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago