Question: ----------------------------------- public class Customer { String firstName,lastName; //constructor public Customer(String firstName,String lastName) { this.firstName=firstName; this.lastName=lastName; } //override toString() method public String toString() { return this.lastName+,

 ----------------------------------- public class Customer { String firstName,lastName; //constructor public Customer(String firstName,StringlastName) { this.firstName=firstName; this.lastName=lastName; } //override toString() method public String toString() {return this.lastName+", "+this.firstName; } boolean equals(Customer obj) { if(this.firstName.equals(obj.firstName) && this.lastName.equals(obj.lastName)) returntrue; else return false; } } ----------------------------------- public class Ingredient { String

-----------------------------------

public class Customer { String firstName,lastName; //constructor public Customer(String firstName,String lastName) { this.firstName=firstName; this.lastName=lastName; } //override toString() method public String toString() { return this.lastName+", "+this.firstName; } boolean equals(Customer obj) { if(this.firstName.equals(obj.firstName) && this.lastName.equals(obj.lastName)) return true; else return false; } }

-----------------------------------

public class Ingredient { String ingredientName; int amount; double price; public Ingredient(String ingredientName,int amount,double price) { this.ingredientName=ingredientName; this.amount=amount; this.price=price; } double getCost() { return amount/1000.0*price; } public String toString() { return this.ingredientName+", "+this.amount+" mls, $"+this.price+"/L"; } }

-----------------------------------

public class TestPhase2 { public static void main(String[] args) { Customer bruno = new Customer("Bruno", "Mars"); Customer taylor = new Customer("Taylor", "Swift"); Customer ada = new Customer("Lovelace", "Ada"); System.out.println("Customer1: " + bruno); System.out.println("Customer2: " + taylor); System.out.println("Customer3: " + ada); System.out.println(); Ingredient milk = new Ingredient("Milk", 500, 2.55); Ingredient espresso = new Ingredient("Espresso", 100, 4.05); Ingredient syrup = new Ingredient("Hazelnut Syrup", 30, 13.5); Ingredient soyMilk = new Ingredient("Soy Milk", 500, 4.75);

Drink latte = new Drink("Latte"); latte.addIngredient(milk); latte.addIngredient(espresso); Drink soyLatte = new Drink("Soy Latte"); soyLatte.addIngredient(soyMilk); soyLatte.addIngredient(espresso); Drink hazeLatte = new Drink("Hazelnut Latte"); hazeLatte.addIngredient(milk); hazeLatte.addIngredient(espresso); hazeLatte.addIngredient(syrup); System.out.println("Drink1: " + latte); System.out.println("Drink1 cost $" + latte.calculateCost()); System.out.println(); System.out.println("Drink2: " + soyLatte); System.out.println("Drink2 cost $" + soyLatte.calculateCost()); System.out.println(); System.out.println("Drink3: " + hazeLatte); System.out.println("Drink3 $" + hazeLatte.calculateCost()); System.out.println();

DrinkOrder o1 = new DrinkOrder(bruno, latte, 4.50); DrinkOrder o2 = new DrinkOrder(bruno, hazeLatte, 5.00); DrinkOrder o3 = new DrinkOrder(taylor, soyLatte, 6.00); DrinkOrder o4 = new DrinkOrder(ada, latte, 4.75); System.out.println(o1); System.out.println("Profit: $" + o1.getProfit()); System.out.println("Belongs to Taylor? " + o1.belongsTo(taylor)); System.out.println(); System.out.println(o2); System.out.println("Profit: $" + o2.getProfit()); System.out.println("Belongs to Bruno? " + o2.belongsTo(bruno)); System.out.println(); System.out.println(o3); System.out.println("Profit: $" + o3.getProfit()); System.out.println("Belongs to Taylor? " + o3.belongsTo(taylor)); System.out.println(); System.out.println(o4); System.out.println("Profit: $" + o4.getProfit()); System.out.println("Belongs to Ada? " + o4.belongsTo(ada)); } }

Next, implement the Drink class, which represents the specification for one type of drink. The Drink class should have: Two instance variables: the name of the drink (a String), and an array of Ingredients. Use a simple partially- filled array for this list of ingredients. You may assume that the list will never become full no error checking is needed A constructor that accepts only one parameter, the drink's name (type String) . A method addIngredient(Ingredient) that adds an ingredient to the drink's list of ingredients .A method calculateCost that returns a double representing the total cost of the drink (based on the costs of each individual ingredient) .A toString method that returns a String containing the drink's name and list of ingredients. Each ingredient should appear on a separate line, with a tab (lt) character at the beginning of the line. Then, implement a DrinkOrder class, which represents a particular customer's drink order. This class should have Three instance variables: the customer who ordered the drink (a Customer), the drink requested (a Drink), the amount charged (in S) (a double) A constructor that has three parameters, in the above order, which are used to initialize the three instance variables A method belongsTo Customer) that returns true if the drink order belongs to the customer passed as a parameter and false otherwise A getProfit method that returns a double representing the profit made for this drink (i.e., the shop's financial gain for the drink order in light of the drink's actual cost) A toString method that returns a String containing the customer, amount charged, and drink information (as shown below). You can test your class with TestPhase2.java. You should get the output shown below (plus or minus any different rounding errors due to floating point arithmetic). Customer1: Mars, Bruno Customer2: Swift, Taylor Customer3: Ada, Lovelace Drink1: Latte, Ingredients: Milk, 500 mls, $2.55/L Espresso, 100 mls, $4.05/L Drink1 cost $1.68 Drink2: Soy Latte, Ingredients: Soy Milk, 500 mls, $4.75/L Espresso, 100 mls, $4.05/L Drink2 cost $2.7800000000000002 Drink3: Hazelnut Latte, Ingredients: Milk, 500 mls, $2.55/L Espresso, 100 mls, $4.05/L Hazelnut Syrup, 30 mls, $13.5/L Drink3 $2.085 Mars, Bruno, $4.5: Latte, Ingredients: Milk, 500 mls, $2.55/L Espresso, 100 mls, $4.05/L Profit: $2.8200000000000003 Belongs to Taylor? false Mars, Bruno, $5.0: Hazelnut Latte, Ingredients: Milk, 500 mls, $2.55/L Espresso, 100 mls, $4.05/L Hazelnut Syrup, 30 mls, $13.5/L Profit: $2.915 Belongs to Bruno? true Swift, Taylor, $6.0: Soy Latte, Ingredients: Soy Milk, 500 mls, $4.75/L Espresso, 100 mls, $4.05/L Profit: $3.2199999999999998 Belongs to Taylor? true Ada, Lovelace, $4.75: Latte, Ingredients: Milk, 500 mls, $2.55/L Espresso, 100 mls, $4.05/L Profit: $3.0700000000000003 Belongs to Ada? true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!