Answered step by step
Verified Expert Solution
Question
1 Approved Answer
**Please write in code in Java!!** 4. The menu at a lunch counter includes a variety of sandwiches, salads, and drinks. The menu also allows
**Please write in code in Java!!**
4. The menu at a lunch counter includes a variety of sandwiches, salads, and drinks. The menu also allows a customer to create a "trio," which consists of three menu items: a sandwich, a salad, and a drink. The price of the trio is the sum of the two highest-priced menu items in the trio; one item with the lowest price is free. Each menu item has a name and a price. The four types of menu items are represented by the four classes Sandwich, Salad, Drink, and Trio. All four classes implement the following MenuItem interface. public interface MenuItem { /** @return the name of the menu item */ String getName(); /** @return the price of the menu item */ double getPrice(); } The following diagram shows the relationship between the MenuItem interface and the Sandwich, Salad, Drink, and Trio classes. interface MenuItem Sandwich Salad Drink Trio For example, assume that the menu includes the following items. The objects listed under each heading are instances of the class indicated by the heading. Sandwich Salad Drink "Cheeseburger" 2.75 "Spinach Salad" 1.25 "Orange Soda" 1.25 "Coleslaw" "Club Sandwich" 2.75 "Cappuccino" 3.50 1.25 The menu allows customers to create Trio menu items, each of which includes a sandwich, a salad, and a drink. The name of the Trio consists of the names of the sandwich, salad, and drink, in that order, each separated by "/" and followed by a space and then "Trio". The price of the Trio is the sum of the two highest-priced items in the Trio; one item with the lowest price is free. A trio consisting of a cheeseburger, spinach salad, and an orange soda would have the name "Cheeseburger/Spinach Salad/Orange Soda Trio" and a price of $4.00 (the two highest prices are $2.75 and $1.25). Similarly, a trio consisting of a club sandwich, coleslaw, and a cappuccino would have the name "Club Sandwich/Coleslaw/Cappuccino Trio" and a price of $6.25 (the two highest prices are $2.75 and $3.50). Write the Trio class that implements the MenuItem interface. Your implementation must include a constructor that takes three parameters representing a sandwich, salad, and drink. The following code segment should have the indicated behavior. Sandwich sandwich; Salad salad; Drink drink; /* Code that initializes sandwich, salad, and drink */ Trio trio = new Trio (sandwich, salad, drink); 1/ Compiles without error Trio triol = new Trio (salad, sandwich, drink); // Compile-time error Trio trio2 = new Trio (sandwich, salad, salad); // Compile-time error Write the complete Trio class belowStep 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