Absolute Java (6th Edition)
Absolute Java (6th Edition)
6th Edition
ISBN: 9780134041674
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 12PP

This programming project extends Programming Project 4.11. Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in Programming Project 4.11. In addition to appropriate instance variables and constructors, add the following methods:

public void setNumPizzas  int numPizzas —sets the number of pizzas in the order. numPizzas must be between 1 and 3.

public void setPizza1 (Pizza pizza1) —sets the number of pizzas in the order.

public void setPizza2 (Pizza pizza2) —sets the second pizza in the order.

public void setPizza3 (Pizza pizza3) —sets the third pizza in the order.

public double calcTotal() —returns the total cost of the order.

Write a main method to test the class. The setPizza2 and setPizza3 methods will be used only if there are two or three pizzas in the order, respectively. Sample code illustrating the methods is shown below. Note that first three lines are incomplete. You must complete them as part of the Programming Project.

Pizza pizza1 = / /  Code to create a large pizza, 1 cheese, 1 ham Pizza pizza2 = / /  Code to create a medium pizza, 2 cheese, 2 pepperoni PizzaOrder order = / /  Code to create an order order .setNumPizzas(2);  / / 2  pizzas in the order order .setPizzal(pizza1);  / /  Set first pizza order .setPizza2(pizza2);  / /  Set second pizza double total = order .calcTotal(); // Should be  18 + 20 = 38

Blurred answer
Students have asked these similar questions
Write a method toString() for the Cow class which displays information about a Cow object. The method should consider the following: • If the Cow's stomach value is 100, the output should say that the Cow is full • If the Cow's stomach value is below 100 but above 50, no information about the Cow's stomach should be given • If the Cow's stomach value is below 50 but above 10, the output should mention that the cow is hungry • If the Cow's stomach value is below 10, the output should mention that the cow is starving. Example output: First Cow is full. Second Cow Third Cow is hungry. Fourth Cow is starving!
Animals need energy to move. They get energy from eating food while moving consumes energy. Create a class Animal with a constructor that takes no parameters and has an instance variable: private int energy; When an animal is "born," it has one unit of energy. It has the methods public void eat(int amountToEat) - which increases the amount of energy the animal has by amountToEat public void move(int amountToMove) - which decreases the energy the animal has by amountToMove. public int getEnergy() - which returns the amount of energy left Notice there is no setEnergy method. Energy is only changed by eating or moving. Since it isn't realistic for animals to be able to gather infinite amounts of energy, to have negative energy or to eat or move a negative amount, you should create a subclass BetterAnimal which has a cap on the amount of energy an animal can have.  The constructor takes a parameter that specifies a maximum for energy. You will need to save this in another instance…
ANSWER IN JAVA Create a class called Date that includes three instance variables-a month (type int), a day (type int) and a year (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes (/). Add a main method to the class that demonstrates class Date's capabilities.

Chapter 4 Solutions

Absolute Java (6th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License