Write a program that will be used to keep track of orders


Detailed Question: Cannot use break; or continue; in answers.

Part A: Order up

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.

Part B: Order up, continued

For this question, you will continue to refine your "Order up" program from the previous question.

The first change will be the addition of two new types of products that can be ordered: sandwiches and pop. This gives you a total of four products. These two new products will need new classes, plus additional modifications to the class hierarchy with one or more new abstract class(es).

Sandwich orders are constructed with following information:

-quantity (int) - how many sandwiches are being ordered

-price (double) - price per sandwich (all sandwiches in the order have the same price)

-filling (String) - what's going in the sandwich (for all in the order)

-bread (String) - the type of bread to use for the sandwich (for all in the order)

Pop orders are constructed with the following information:

-quantity (int) - how many drinks are being ordered

-size (String) - the size of the drinks (all drinks in the order have the same size)

-brand (String) - the brand of pop being ordered

The new classes will need constructors and toString methods. The toString should include in its results the type of order, plus the value of all instance variables.

The size of a pop order determines its price. There are three sizes, with the following prices:

-small is $1.79

-medium is $2.09

-large is $2.49

You can assume that when you construct a pop order, one of those three strings will be passed as the size of the drinks in the order.

Your classes should have a method called totalPrice(), which returns the total price of the order, calculated as before. All sandwich orders have 7% tax applied to their price, regardless of the order size. The drinks do not, and the donuts have the same rule as before (7% tax if there are fewer than 6 donuts in the order).

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. The principles of good object-oriented programming will be enforced strictly in this assignment.

The second change will be the use of a collection class to store the data. The collection will still contain an ArrayList, but it should also include instance methods that ensure only your order subclasses can ever be inserted into the collection. You may also wish to put some of the processing in your methods for that class.

The third change will be the addition of a sort() method, which will be an instance method in your collection class. It should sort the items in the collection by total price, in ascending order (smallest to largest price).

Your program will read in orders from a text file, create objects, and store them in the collection. Each line of the file starts with the word "Coffee", "Donut", "Pop", or "Sandwich", 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

Pop,5,large,Splat! Cola

Sandwich,1,3.89,mystery meat,37-grain whole wheat

Once your program has read in the values and stored them in the collection, 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.

-Sort the order by calling the sort method.

-Print the items again, with total price, as you did in the first step.

-Print the total quantity of donuts in all the orders, all the coffees, all the pops, and all the sandwiches

-Print the total of all the prices of all the orders.

Use the data file a4b.txt to test your program.

Attachment:- Assignment.rar

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a program that will be used to keep track of orders
Reference No:- TGS01672660

Expected delivery within 24 Hours