he 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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 3GZ
icon
Related questions
icon
Concept explainers
Question

Question 1. 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. 

import java.text.*; 

import java.util.*; 

class SimpleLunchItem 

private String name; 

private double price; 

public SimpleLunchItem(String aName, double aPrice) 

name = aName; 

price = aPrice; 

public String getName() { return name; } 

public double getPrice() { return price; } 

public String toString () 

DecimalFormat money = new DecimalFormat("0.00"); 

return getName() + " " + money.format(getPrice()); 

class Drink extends SimpleLunchItem 

public Drink(String name, double price) 

{ super(name, price); } 

class Salad extends SimpleLunchItem 

public Salad(String name, double price) 

{ super(name, price); } 

class Sandwich extends SimpleLunchItem 

public Sandwich(String name, double price) 

{ super(name, price); } 

// Declare the Trio class 

// declare the instance variables that you need for a trio object 

// write a constructor that takes a Sandwich, Salad, and a Drink, in that order 

// write the getName method it should return sandwich name/salad name/drink name 

// write the getPrice method it should return the sum of price of the two highest price items in the trio. 

public static void main(String[] args) 

Sandwich burger = new Sandwich("Cheeseburger",2.75); 

Sandwich club = new Sandwich("Club Sandwich", 2.75); 

Salad spinachSalad = new Salad("Spinach Salad",1.25); 

Salad coleslaw = new Salad("Coleslaw", 1.25); 

Drink orange = new Drink("Orange Soda", 1.25); 

Drink cap = new Drink("Cappuccino", 3.50); 

Trio trio1 = new Trio(burger,spinachSalad, orange); 

System.out.println("It should print Cheeseburger/Spinach Salad/Orange Soda and it prints: " + trio1.getName()); 

System.out.println("It should print 4.0 and it prints: " + trio1.getPrice()); 

Trio trio2 = new Trio(club,coleslaw,cap); 

System.out.println("It should print Club Sandwich/Coleslaw/Capuccino and it prints: " + trio2.getName()); 

System.out.println("It should print 6.25 and it prints: " + trio2.getPrice()); 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,