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

  Build application and activate the camera for android mobile

The proposed idea build application and activate the camera for android mobile and take picture and put animation on someone face

  1obtaining the new script download and save the attached

1.obtaining the new script download and save the attached comment cgi mailer script form-mail.pl to your servers

  1 comparing portions of strings write an application that

1. comparing portions of strings write an application that uses string method region-matches to compare two strings

  Write java program using array list object

Write a java program (using eclipse) using ArrayList object to allow the professor to enter student's name, his or her's four test scores.

  Write a payroll applicaion in java

The program should allow the user to enter information for any number of employees in this manner.

  Create a new project called fractions

You are going to write an API for a Fractions class. It will accept fractions as input and perform various mathematical operations on them -  Create a new project called Fractions. Within Fractions, create a new class called Fraction. NetBeans will..

  Writing a program to calculate state income tax

The second programming project involves writing a program to calculate state income tax for a single taxpayer that uses a GUI. The GUI should use the grid layout manager and should looks similar to the following: The salary income, interest income..

  Write a string expression that parenthesizes the value

Given a string varible word, write a string expression that parenthesizes the value of word. So if the word contains "sadly" the value of the expression would be the string "(sadly)".

  Write a java servlet to validate the data

Write a Java Servlet to validate the data submitted through the above registration page. If the required fields are empty relevant error messages should be displayed on the same registration page.

  Write a java application that allows a user to enter numbers

Write a Java application that allows a user to enter numbers into an array and then process them. Enter the number of elements and the value of each element

  Positive integer number

There is a homework to create a program that takes in a positive integer number from the user and searches for the number with the highest sum of divisors from the 1 to the user imputed number. The program then has to output the number in this range ..

  How are java source code files named

What is the purpose of the wait(), notify(), and notifyAll() methods? How are Java source code files named?

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