Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: A store sells FroYoCups with space for 5 FoodItems (FroYo or Toppings). The store owner hired a student during summer of 2018 to help

JAVA: 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.

Food items:

FoodItem.java

package food ;

public abstract class FoodItem implements GetFoodDetails {

private String name ;

private int caloriesPerServing ;

private double weightPerServing ;

public FoodItem ( String name , int caloriesPerServing , double weightPerServing ) {

this . name = name ;

this . caloriesPerServing = caloriesPerServing ;

this . weightPerServing = weightPerServing ;

}

public String getName () {

return this . name ;

}

public int getCaloriesPerServing () {

return caloriesPerServing ;

}

@Overridepublic String toString () {

return this . getName () + " (" + getCalories () + " kcal /" + getWeight () + "g)";

}

}

GetFoodDetails.java

package food ;

public interface GetFoodDetails {

int getCalories (); // full kcals

double getWeight (); // weight in grams

}

Topping.java

package food ;

public class Topping extends FoodItem implements GetFoodDetails {

public Topping ( String name , int caloriesPerServing , double weightPerServing ) {

super (name , caloriesPerServing , weightPerServing );

}

@Override

public int getCalories () {

return this . getCaloriesPerServing ();

}

@Override

public double getWeight () {

return 0;

}

}

ToppingList.java

package food ;

public interface ToppingList {

public static final Topping MANDMS = new Topping ("M&Ms", 240 , 48);

public static final Topping REESES = new Topping (" Reeses Mini Cups ", 200 , 39);

public static final Topping ALMONDS = new Topping ("Raw Almonds ", 163 , 28);

public static final Topping PEANUTS_RAW = new Topping ("Raw Peanuts ", 161 , 28);

public static final Topping PEANUTS_ROASTED = new Topping (" Roasted Peanuts ", 248 , 42);

}

Froyo.java

package food ;

public class Froyo extends FoodItem {

public Froyo ( String name , int caloriesPerServing , double weightPerServing ) {

super (name , caloriesPerServing , weightPerServing );

}

@Override

public int getCalories () {

return 0;

}

@Override

public double getWeight () {

return 0;

}

}

Store Items:

Checkout.java

package shoppe ;

public interface Checkout {

double PRICE_PER_OZ = 1.00;

double TAX_RATE = 6; // 6% tax rate

int MAX_ITEMS = 5; // 5 items that fit in a cup

int getWeight ();

int totalCalories ();

double weightToDollars ( double weightInGrams );

double taxAmount ( double preTaxDollars );

}

FroYoCup.java

package shoppe ;

import java.util.ArrayList;

import food.FoodItem;

public class FroYoCup implements Checkout {

ArrayList < FoodItem > contents ;

public FroYoCup () {

this.contents = new ArrayList < >();

}

public boolean addItem ( FoodItem item ) {

if ( contents . size () < Checkout . MAX_ITEMS ) {

contents .add( item );

return true ;

}

return false ;

}

}

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions