Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92024608
  • Price:- $80

Guranteed 48 Hours Delivery, In Price:- $80

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As