Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use only java please, if you do not know do not answer. In this assignment, you will practice solving a problem using object-oriented programming language

use only java please,

if you do not know do not answer.

In this assignment, you will practice solving a problem using object-oriented programming language java and specifically, you will use the concept of object composition (i.e., has-a relationship between objects). You will implement a Java application, called OrderHub that could be used by a food delivery company. You are asked to implement four classes: MenuItem, Driver, Order, and OrderRunner. Each of these classes is described below

1 Program description

1.1 MenuItem

The MenuItem class represents one item ordered from 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. The 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 the 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 restaurant instance 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 restaurant instance 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 String which represents the name of the MenuItem. This method searches the array and returns the existing MenuItem if found and null if 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 double which 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%) 2 ICS 240 Introduction to Data Structures Spring 2021 the Order total after tax and tip. the Driver of the Order

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.

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

Step: 3

blur-text-image

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

Recommendations on how debt-management may be improved in belize

Answered: 1 week ago

Question

2. How can competencies be used in employee development?

Answered: 1 week ago