Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help fixing/adding to this java code... Practice: A store sells FroYoCups with space for 5 FoodItems (FroYo or Toppings). The store owner hired a

Need help fixing/adding to this java code...

Practice: A store sells FroYoCups with space for 5 FoodItems (FroYo or Toppings). The store owner hired a student during summer of 2018 to help with a simple program that can help to quickly print out a customers order and the detailed items that a customer has added to their cup, including calories and taxes for a detailed bill. Sadly, the student went on to eat too much of the free froyo (brain freeze!!!) and left the code only partially finished. While all toppings were found in the code, it seems that the vanilla, chocolate, and taro flavors of froyo are missing: Vanilla has a weight of 72 g and 114 kcal. Chocolate weighs as much as vanilla and has 115 calories. Taro weighs as much as the other two and has 95 calories.

Use the following code snippets with a Main class to demonstrate with 3 different FroYo/Topping combinations of your choice how you were able to take the given code and turn it into a working program.

Note: There are no comments included in the code to make you go through and comment yourself as you work your way to an implementation. Note 2: There are some dummy values utilized in the demo code, and some classes might be missing, too.

1.1 Food Items

Listing 1: FoodItem.java

1 package food; 2 3 public abstract class FoodItem implements GetFoodDetails { 4 private String name; 5 private int caloriesPerServing; 6 private double weightPerServing; 7 8 public FoodItem (String name , int caloriesPerServing , double weightPerServing) { 9 this.name = name; 10 this.caloriesPerServing = caloriesPerServing; 11 this.weightPerServing = weightPerServing; 12 } 13 14 public String getName() { 15 return this.name; 16 } 17 18 public int getCaloriesPerServing() { 19 return caloriesPerServing; 20 } 21 22 @Override 23 public String toString() { 24 return this.getName() + " (" + getCalories () + " kcal /" + getWeight () + "g)"; 25 } 26 }

Listing 2: GetFoodDetails.java

1 package food; 2 3 public interface GetFoodDetails { 4 int getCalories(); // full kcals 5 double getWeight(); // weight in grams 6 }

Listing 3: Topping.java

1 package food; 2 3 public class Topping extends FoodItem implements GetFoodDetails { 4 5 public Topping(String name, int caloriesPerServing, double weightPerServing) { 6 super (name , caloriesPerServing , weightPerServing); 7 } 8 9 @Override 10 public int getCalories() { 11 return this.getCaloriesPerServing(); 12 } 13 14 @Override 15 public double getWeight() { 16 return 0; 17 } 18 }

Listing 4: ToppingList.java

1 package food; 2 3 public interface ToppingList { 4 public static final Topping MANDMS = new Topping ("M&Ms", 240 , 48); 5 public static final Topping REESES = new Topping (" Reeses Mini Cups ", 200 , 39); 6 public static final Topping ALMONDS = new Topping ("Raw Almonds ", 163 , 28); 7 public static final Topping PEANUTS_RAW = new Topping ("Raw Peanuts ", 161 , 28); 8 public static final Topping PEANUTS_ROASTED = new Topping (" Roasted Peanuts ", - 248 , 42); 9 }

Listing 5: Froyo.java

1 package food ; 2 3 public class Froyo extends FoodItem { 4 public Froyo (String name, int caloriesPerServing, double weightPerServing) { 5 super (name, caloriesPerServing, weightPerServing); 6 } 7 8 @Override 9 public int getCalories() { 10 return 0; 11 } 12 13 @Override 14 public double getWeight() { 15 return 0; 16 } 17 }

1.2 Store Items

Listing 6: Checkout.java

1 package shoppe; 2 3 public interface Checkout { 4 double PRICE_PER_OZ = 1.00; 5 double TAX_RATE = 6; // 6% tax rate 6 int MAX_ITEMS = 5; // 5 items that fit in a cup 7 8 int getWeight(); 9 int totalCalories(); 10 double weightToDollars(double weightInGrams); 11 double taxAmount(double preTaxDollars); 12 }

Listing 7: FroYoCup.java

1 package shoppe ; 2 3 import java.util.ArrayList ; 4 5 import food.FoodItem ; 6 7 public class FroYoCup implements Checkout { 8 ArrayList contents ; 9 10 public FroYoCup() { 11 this.contents=new ArrayList<>(); 12 } 13 14 public boolean addItem(FoodItem item) { 15 if (contents.size() < Checkout.MAX_ITEMS) { 16 contents.add(item); 17 return true; 18 } 19 return false; 20 } 21 }

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago