Write a Java program that implements the following classes: 1. The following class Menu which represents a menu (plab ii) in a restaurant: Menu - meals: String) - prices: double (] - timesOrdered: int [] - numOfMenusCreated: int + Menu( ) + Menu(m: Menu) + getMeals (:String[] + setPrice(p:double, index:int): void

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Java language
Write a Java program that implements the following classes:
1. The following class Menu which represents a menu (plaba iali) in a restaurant:
Menu
- meals: String[]
- prices: double (]
- timesOrdered: int []
- numOfMenusCreated: int
+ Menu( )
+ Menu(m: Menu)
+ getMeals ():String()
+ setPrice(p:double, index:int): void
+ getPrices():double[]
+ incrementTimesOrdered(int index): void
+ getTimesOrdered(index:int): int
+ getNumOfMenusCreated 0: int
+ getMostOrderedMeal(): String
+ ptintMenu(): void
a. The no-arg constructor must:
- Read the number of meals from the user.
- Initialize the arrays meals, prices, and timesOrdered by creating them with the entered size.
- Read the meals (names) and prices from the user.
- The timesOrdered array elements should be initialized to 0.
- Increment the data field numOfMenusCreated.
b. The constructor Menu(m:Menu) must:
- Initialize the arrays meals, prices, and timesOrdered by creating them with the same size as the arrays
meals, prices, and timesOrdered of the passed Menu object.
- Copy the meals (names) and prices from the meals and prices arrays of the passed object.
- The timesOrdered array elements should be initialized to 0.
- Increment the data field numOfMenusCreated.
c. The method setPrice must set the element whose index is passed, of the array prices, with the passed
double value p. The method should only allow the price to be modified if the value of p is positive
and nonzero.
d. The method getPrices must return the prices, but not by returning the reference of the array prices,
it must return a reference to a copy of the prices array.
Transcribed Image Text:Write a Java program that implements the following classes: 1. The following class Menu which represents a menu (plaba iali) in a restaurant: Menu - meals: String[] - prices: double (] - timesOrdered: int [] - numOfMenusCreated: int + Menu( ) + Menu(m: Menu) + getMeals ():String() + setPrice(p:double, index:int): void + getPrices():double[] + incrementTimesOrdered(int index): void + getTimesOrdered(index:int): int + getNumOfMenusCreated 0: int + getMostOrderedMeal(): String + ptintMenu(): void a. The no-arg constructor must: - Read the number of meals from the user. - Initialize the arrays meals, prices, and timesOrdered by creating them with the entered size. - Read the meals (names) and prices from the user. - The timesOrdered array elements should be initialized to 0. - Increment the data field numOfMenusCreated. b. The constructor Menu(m:Menu) must: - Initialize the arrays meals, prices, and timesOrdered by creating them with the same size as the arrays meals, prices, and timesOrdered of the passed Menu object. - Copy the meals (names) and prices from the meals and prices arrays of the passed object. - The timesOrdered array elements should be initialized to 0. - Increment the data field numOfMenusCreated. c. The method setPrice must set the element whose index is passed, of the array prices, with the passed double value p. The method should only allow the price to be modified if the value of p is positive and nonzero. d. The method getPrices must return the prices, but not by returning the reference of the array prices, it must return a reference to a copy of the prices array.
e. The method incrementTimesOrdered must increment the element in the array timesOrdered with
the passed index.
f. The method getMostOrderedMeal must return the name of the meal which was most ordered based
on the timesOrdered array.
g. The method printMenu must print the meals index-name-price each on a new line, then print the
name of the most ordered meal by invoking the getMostOrderedMeal method. An example output:
0- Chicken Burger – 3.5
1-Vegetarian Pizza – 6
Most ordered meal: ..
Transcribed Image Text:e. The method incrementTimesOrdered must increment the element in the array timesOrdered with the passed index. f. The method getMostOrderedMeal must return the name of the meal which was most ordered based on the timesOrdered array. g. The method printMenu must print the meals index-name-price each on a new line, then print the name of the most ordered meal by invoking the getMostOrderedMeal method. An example output: 0- Chicken Burger – 3.5 1-Vegetarian Pizza – 6 Most ordered meal: ..
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY