Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA PROBLEM Here is the code copy and pasted: package patt.Coffee ; public class CoffeeEnums { public static enum Type { LONG_BLACK ( 4.0 ),
JAVA PROBLEM
Here is the code copy and pasted:
package patt.Coffee; public class CoffeeEnums { public static enum Type { LONG_BLACK(4.0), FLAT_WHITE(4.75), MOCHA(5.5); private double price; Type(double price) { this.price = price; } public double getPrice() { return price; } } public static enum Ingredient { ESPRESSO(0.5), MILK(1), CHOCOLATE(1.5); private double cost; Ingredient(double cost) { this.cost = cost; } public double getCost() { return cost; } } }
package patt.Coffee; import java.util.ArrayList; public class Coffee { String type; double cost; ArrayListString> ingredients; public Coffee(ArrayListString> ingredients, String type) { this.type = type; this.ingredients = ingredients; double sum = 0; for (String ingredient : ingredients) { if (ingredient == "espresso") { sum += 0.5; } else if (ingredient == "milk") { sum += 1.0; } else if (ingredient == "chocolate") { sum += 1.5; } else { sum += 0; } } this.cost = sum; } public double getCost() { return cost; } public double getPrice() { if (this.type.equals("long black")) { return 4.0; } else if (this.type.equals("flat white")) { return 5.0; } else if (this.type.equals("mocha")) { return 6.0; } return 0; } public String listIngredients() { String string = ""; for (String ingredient : ingredients) { string += ingredient; string += " "; } return string; } }Requirements Susan owns a caf and hired a programmer to build a system for her baristas to enter customer orders and maintain inventory. One of the classes the programmer has written as part of the larger system is Coffee (provided) You should inspect this class yourself to understand how it works. Note that cost" refers to the ingredient cost on Susan's behalf, and price" refers to the price a customer pays for a particular coffee. After Susan took one look at the class, she fired the programmer and hired you to refactor it. This class uses a lot of bad practice. Most notably, it relies on the usage of strings. For instance, when interfacing with Coffee, a long black has to be constructed like ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started