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
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…
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…
Modify the student class presented in this chapter as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called getTestScore that accepts the test number and returns the appropriate score Provide a method called average that computes and returns the average test score for this student. Modify the toString method such that the test scores and average are included in the description of the student. Modify the driver class main method to exercise the new Student methods. (Java)

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
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License