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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education