Question: Java Code Part A: Order up ( Please write coments in program) Write a program that will be used to keep track of orders placed
Java Code
Part A: Order up ( Please write coments in program)
Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass.
Coffee orders are constructed with the following information:
quantity (int) - how many coffees are being ordered
size (String) - the size of the coffees (all coffees in the order have the same size)
Donut orders are constructed with following information:
quantity (int) - how many donuts are being ordered
price (double) - price per donut (all donuts in the order have the same price)
flavour (String) - the flavour of donut (all donuts in the order have the same flavour)
The two order types need constructors and toString methods. The toString should include in its results the type of order ("Coffee" or "Donut"), plus the value of all instance variables.
The size of a coffee determines its price. There are three sizes, with the following prices:
small is $1.39
medium is $1.69
large is $1.99
You can assume that when you construct a coffee order, one of those three strings will be passed as the size of the coffees in the order.
Your classes should have a method called totalPrice(), which returns the total price of the order. Total price is generally equal to price per unit times the quantity; however, orders of donuts with a quantity of less than 6 should have a 7% tax added to the total price. There is no tax on coffee orders, or donut orders with 6 or more donuts.
Use inheritance to prevent duplicate code. Make all your instance variables private, and write getter/setter methods only when necessary. Do not store total price as an instance variable, as it can be calculated when needed.
Your program will read in orders from a text file, create objects, and store them in a single ArrayList of objects of your classes. Each line of the file starts with the word "Coffee" or "Donut", and then provides values for the instance variables for an order of that type, separated by commas, in the same order given above. There will not be any errors in the file.
Coffee,3,medium Donut,7,0.89,chocolate
Once your program has read in the values and stored them in the ArrayList, it should do the following:
Print the complete contents of the list (i.e. all the orders). Show both the results of the toString() and the total price of that order.
Print the total quantity of donuts in all the orders, and the total quantity of coffees in all the orders.
Print the total of all the prices of all the orders.
Use the data file a4a.txt to test your program.
a4a.txt:
Coffee,3,medium Donut,7,0.89,chocolate Donut,3,1.19,eclair Coffee,1,large Coffee,2,large Coffee,7,small Donut,6,0.89,baker's choice Donut,1,1.10,lemon buster Donut,120,0.15,petite oeufs Coffee,10,medium
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
