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

  Display the program output of the collision results

According to my lecturer, I need the tutor to display the 'program output' of the collision results implemented by BirthdayAttack.java in a output.txt file. Can the tutor do this?

  Number of primes

Write a program BackwardPrimes.java that prompts user for a positive integer number x and displays x prime numbers whose reversal is also a prime. Numbers 13, 31 and 157 are instances of such numbers. Following is a sample run of your program.

  Define java implementation to implement the requirements

Produce a Java implementation to implement the requirements of Question 1, that is, to perform the 32-bits two complement and 32-bit floating-point conversion of a given number.

  Write a client server program using tcp sockets

1) Write a client server program using TCP where client sends two numbers and server responds with sum of them.2) Write a client-server program using TCP sockets to echo the message send by the client.

  How are exceptions caught

How are exceptions caught? When should Exception Handling be used

  Write ijvm program to multiply two hexadecimal numbers

Write the IJVM program that multiplies two (hexadecimal) numbers. The user inputs the hex numbers and the result is printed out. The program then accepts another pair of numbers.

  Solve the currently very un-pc cigarette smokers problem

Write solution to solve the currently very un-PC"cigarette smokers problem" in java using Java threads, and monitors (using the "synchronized" keyword) (If it bothers your PC sensibilities, think of it at the Pot-smokers problem and then it is all pr..

  Round the average score to one decimal

The number format in one decimal place to make this to round the average score to one decimal in this program.

  Develop and test stand alone java applications

Demonstrate an understanding of Object-Oriented Programming concepts in Java.

  1write a program that uses joptionpanes to perform the

1.write a program that uses joptionpanes to perform the following stepsmiddotfirst display a welcome message to your

  Implementation of the vector data type

Described in general terms the implementation of the vector data type. Complete the implementation of the vector by providing definitions for the subsequent operations

  Create the default junit tests using netbeans

Create the 'default' JUnit tests using NetBeans. Do this for the HomeAppliance class only; not for your JFrame GUI class.

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