Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# 1 To do: You work at a coffee shop where you take drink orders. Create a class named Drinks with the following fields. Make

# 1

To do:

You work at a coffee shop where you take drink orders. Create a class named Drinks with the following fields. Make certain to include all methods required in our class blueprint.

private String drinkType;

private char size; (//NOTE valid values are S, M, or L for small, medium, large) private double costEach; private int numOrdered;

We are going to create an array of Drink instances in a driver named DrinkDriverArray and fill in data from the keyboard. We do not know how many there are ahead of time. We have examples of how to handle arrays of unknown size. . NOTE: it MUST be an array not an ArrayList. Lets assume that we will not have over 20 different drink orders so make your program to handle any number of them up to 20 (you do not need to write an increaseSize() method).

The main loop should just be reading in the data by asking the user for values for the four fields, creating the instances and placing them in the array. You can end the loop any way that you like.

Create methods shown in the UML diagram above.

(NOTE: since these methods are related to multiple orders, they must go in the driver class not the blueprint. The only thing that can go into the blueprint is anything that has to do with ONE Drink order.

After your loop in main(), call the three methods in d. above to print out the data and summaries.

HINT: since we do not know the size of the array, you will need a counter and each of the three methods above will have parameters of the Ticket array..

#2

To do: We will now write a driver using ArrayLists for our Drink class from above. Make DrinkDriverArray and name it DrinkDriverArrayList. Convert this program from an array collection to an ArrayList. You do not need to make any changes in the Drink program.

Sample output from Drinks and DrinksDriverArray (same output for DrinksDriverArrayList)

Enter the type of drink

unsweetened ice tea

What size? (S, M, or L)

L

Enter the cost of each drink:

2.30

Enter the number of these drinks purchased:

4

Enter another drink order? (yes or no)

yes

Enter the type of drink

black coffee

What size? (S, M, or L)

M

Enter the cost of each drink:

3.10

Enter the number of these drinks purchased:

2

Enter another drink order? (yes or no)

no

The orders are:

You ordered 4 large unsweetened ice tea at $2.30 for each drink. The total cost was $9.20

You ordered 2 medium black coffee at $3.10 for each drink. The total cost was $6.20

The total number of tickets purchased is 6.

The cost of all the drinks purchased for all orders is $15.40

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions