Question: In this assignment, you will be writing a program to check the nutrition values of a meal for Old Country Buffet. Old Country Buffet offers
In this assignment, you will be writing a program to check the nutrition values of a meal for Old Country Buffet. Old Country Buffet offers the following type of food:
- Bakery
- Entree
- Drink
Each food has a name and label. Bakery has an extra attribute pieces, and Drink has an extra attribute volume. The calories of each serving can be determined by the following table:
| L | M | S | |
| Bakery | 300/piece | 200/piece | 100/piece |
| Entree | 400 | 300 | 200 |
| Drink | 3/ml | 2/ml | 0/ml |
All of your classes should be defined in chapter9.nutrition package. You should also implement a class named Plate, which has the following methods:
- addItem(FoodItem item)
- display()
- getTotalCalories()
Your implementation should work for PlateTest.java, and PlateTest should produce the following output(so you can figure out what to output in display method for each class):
Name:.Steak Label:.L Calories:400 Name:.Sprite Label:.L Calories:300 Volume:.100 Name:.Ice.Tea Label:.M Calories:160 Volume:.80 Name:.Bread Label:.L Calories:300 Pieces:.1 Name:.Croissant Label:.M Calories:400 Pieces:.2 Total:.1560
We were given this:
package chapter9.nutrition; /** * Do not make any changes to this class. * Make sure that you move the file to the appripriate folder. */
public abstract class FoodItem { protected String name; protected String label;
public FoodItem(String name, String label) { this.name = name; this.label = label; }
public String getName() { return name; }
public String getLabel() { return label; }
public void display() { System.out.println("Name: " + name); System.out.println("Label: " + label); System.out.println("Calories:" + getCalories()); }
public abstract int getCalories(); }
and this :
/** * Do not modify this file, otherwise * you will not pass the first testcase. */
import chapter9.nutrition.Plate; import chapter9.nutrition.FoodItem; import chapter9.nutrition.Drink; import chapter9.nutrition.Bakery; import chapter9.nutrition.Entree;
public class PlateTest {
public static void main(String[] args) { Plate plate = new Plate(); plate.addItem(new Entree("Steak", "L"));
plate.addItem(new Drink("Sprite", "L", 100));
plate.addItem(new Drink("Ice Tea", "M", 80));
plate.addItem(new Bakery("Bread", "L", 1));
plate.addItem(new Bakery("Croissant", "M", 2));
plate.display(); System.out.println("Total: " + plate.getTotalCalories()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
