Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Program description 1.1 MenuItem The MenuItem class represents one item ordered fraom a menu. It has three instance variables: name of type String, price

1 Program description

1.1 MenuItem

The MenuItem class represents one item ordered fraom a menu. It has three instance variables: name of type

String, price of type double, and quantity of type int.

Implement the following methods for the MenuItem class:

Constructor to initialize all variables. A value for each instance variable will be passed as arguments to the constructor. The arguments must be in the order of name, price, and quantity.

Getters for all instance variables.

Setter for the quantity instance variable.

equals() a method to test the equality of two items. Two items are considered to be equal if they have the same name. Comparison must be case insensitive.

toString() a method that returns a nicely formatted string description of the item. Each item should be separated by a tab (use \t) and the entire MenuItem should be displayed on one line. In addition to name, price, and quantity, calculate the total cost of the MenuItem (price * quantity) and add it to the end of the string:

Fries $1.95 2 $3.90

Use the NumberFormat or DecimalFormat to display prices with exactly two digits after the decimal.

1.2 Driver

The Driver class represents the delivery driver for an order. It has three instance variables: id of type int,

name of type String and vehicle of type String.

Implement the following methods for the Driver class:

Constructor to initialize all variables. A value for each instance variable will be passed as arguments to the constructor. The arguments must be in the order of id, name and vehicle.

Getters for all instance variables.

Setters for name and vehicle.

equals() a method to test the equality of two items. Two items are considered equal if they have the same id.

toString() a method that returns a nicely formatted description of the item.

1.3 Order

The Order class represent a customers order. It is a collection of MenuItem and an associated Driver. It has four private instance variables:

restaurant a String that represents the restaurant name.

items an instance variable of type array of MenuItem.

numItems an instance variable of type int which represents the number of items that have been added to the Order.

driver an instance variable of type Driver.

Implement the following public methods for the Order class:

A constructor that has one argument, the name of the restaurant. It sets the restaurantinstance variable to the value passed in the constructor, initializes the array of MenuItem to a length of your choosing, sets numItems to 0, and sets driver to null.

A constructor that has two arguments, the name of the restaurant and the initial size of the MenuItem array. It sets the restaurantinstance variable to the value passed in the constructor, initializes the array of MenuItem to the length passed in the constructor, sets numItems to 0, and sets driver to null.

addItem() a method that takes three arguments: name, price, and quantity (in that order). If the MenuItem has already been ordered, this method will increment the existing MenuItem by quantity. If it has not already been ordered, this method creates an instance of MenuItem and adds it to the next available spot in the array. If the array of items is full, you must create a new array of a bigger size and copy all the existing items in the current array to the new array before adding the new item.

find()a method that has on argument of type Stringwhich represents the name of the MenuItem. This method searches the array and returns the existing MenuItemif found and nullif it is not found. find() must call the equals() method of the MenuItem class.

getTotalBeforeTax() which returns the total cost of all items in the order.

getTax()a method with one argument a doublewhich represents the tax rate and returns the calculated tax as a double.

getTip() a method with one argument a double which represents the tip percentage and returns the calculated tip as a double.

getMenuItemsCount() a method with no arguments which returns the number of MenuItem in the order.

getTotalItems()a method with no arguments which returns the total of all quantities of all the MenuItem.

toString() a method which returns a string representation of the Order that includes the following:

restaurants name

details of all the MenuItem, one per line

the Order total before tax and tip.

the amount of tax to be added (use fixed rate of 8%)

the amount of tip to be added (use fixed rate of 20%)

the Order total after tax and tip.

the Driver of the Order

For example:

Downtown Cafe

------------------------------------------------- Item Price Qty Total

------------------------------------------------- Fries $1.95 4 $7.80

Cheeseburger $4.95 4 $19.80

------------------------------------------------- Total: $27.60

Tax: $2.21

Tip: $5.52

------------------------------------------------- Grand Total: $35.33

Delivery Driver: Jane Doe, Toyota Corolla

1.4 OrderRunner

In a separate class, implement a test class:

Create two Orders with your choice of restaurant names.

Add at least three MenuItems to the first Order and at least five MenuItems to the second. Make sure to test the case where the item has already been added and the case where the MenuItem array is full and needs to be expanded.

Add a Driver to each order.

Print both invoices in a nicely formatted output.

Test all other aspects of your program.

Do not use a Scanner to read any inputs from the user.

2 Other Requirements

Draw a UML structure diagram showing the relationship between the classes in your solution. You may hand draw or use any tool of your choice. The diagram must be submitted as an image, e.g. .jpg, .png, etc.

Draw a UML class diagram for your Order, Driver, and MenuItem classes. Best practice is to combine this with the structure diagram, but that is not necessary.

Document all public methods with Javadoc Comments.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions