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

Assignment Help JAVA Programming
Reference no: EM131269877

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

Reference no: EM131269877

Questions Cloud

Process and forms of communication : In this module, you learned about the process and forms of communication as well as the related individual and organizational barriers which may exist.
Compound continuously which is the better investment : Which is the better investment if the rate of the income from the business is f(t) = 2,250.- If both the bond and the continuous income stream earn 3.75%, compounded continuously, which is the better investment?
How many of each of the following are there in the disk : A fixed disk has 80 cylinders. The tracks in each cylinder are numbered 0-11. The upper surface of the topmost platter and the lower surface of the bottommost platter are not used for recording data
Should you buy the tablets today : Your competitors sell the tablet for $41.20 and you must mark you product up from cost by at least 20% to earn a minimal profit, should you buy the tablets today? Explain your answer.
Write a program that will be used to keep track of orders : 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
Produce same future value as the continuous income stream : If the continuous income stream earns 6.95%, compounded continuously, what single deposit into an account earning the same interest rate will produce the same future value as the continuous income stream?
How you will monitor the risks that you have projected : For this assignment, you will determine how you will monitor the risks that you have projected, as well as the unknown risks that occur during the course of the project. You will also formulate a control plan once a risk has been identified during..
What is the potential problem with building too many indexes : What attributes should be considered as candidates for having indexes built on them? What is the potential problem with building too many indexes?
What single deposit into account earning same interest rate : If the continuous income stream earns 6.95%, compounded continuously, what single deposit into an account earning the same interest rate will produce the same future value as the continuous income stream?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Projectyou will design and deliver a website foes fictional

projectyou will design and deliver a website foes fictional client. the project is split into two partspart a website

  Complier error and run time error

Q1. What do you understand by complier error and run time error? Explain by example.

  Write a program called word guessing game.

Write a program called Word Guessing Game. Open the file FourLetterWords.txt and write the contents into an array of Strings (the file has 87 words in it).

  Print two random integers

Type two statements using nextInt() to print two random integers between 0 and 9. End with a newline. Ex:

  Considered to be an improved version

Part (c) is considered to be an improved version of Part (b). You may use an array (2-dimessional) to store some values that has been computed during the run so that when making recursive calls the program does not compute certain values over and ..

  Write a restful web service demo example using spring mvc

Write a restful web service demo example using spring mvc

  Design a class that can be used to hold information

Implement and design a class that can be used to hold information about a musical note - Prepare a complete java program the default constructor should set a note to a middle C quarter note.

  Compare the average completion times of all jobs

Compare the average completion times of all jobs for each scheduling algorithm. Output the details of each algorithm's execution. You need to show which jobs are selected at what times as well as their starting and stopping burst values. You can choo..

  Create a java application

Create a Java application named DistanceCalculator.java to solve the following problem. An application is needed to allow a user to enter two cities and display the distances between them.

  Write a blog article for a codingtechnical community

write a blog article for a codingtechnical community blog.the theme is general c or java. choose any subject under this

  Write a java program that prompts the user

Write a Java program that prompts the user to input three numbers.  This program should then output the numbers in an ascending order.

  Implement simple relational database management system

What would this tuple look like if we stored it in a fixed­length record? Your answer should be a single string of characters that specifies the contents of the record ­­ something similar to the record diagrams in the lecture notes

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd