Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Troop 1043 is having its annual popcorn fundraiser. Scout popcorn is known to be really yummy. Your friend's mom happens to be the popcorn queen

Troop 1043 is having its annual popcorn fundraiser. Scout popcorn is known to be really yummy. Your friend's mom happens to be the popcorn queen and is struggling to find a way to keep track of orders. You are just the person to help out :)

There are a few thing in particular that will be really helpful for the popcorn queen:

keep a master list of the popcorn orders

quickly find the sum of all popcorn orders

quickly find the number of a particular variety

remove the orders of a particular variety as they are being filled

It seems as though the ArrayList will be the perfect way to keep a master list of popcorn orders. As you brainstorm more, you determine that you will create a popcorn class and objects created from that class be stored in the master list.

The PopcornOrder class will be as follows:

Instance Variables:

variety - variety of the popcorn (Jalapeno Cheese, Caramel with Salt, etc.)

quantity - number of that particular variety that has been ordered.

Constructors

no default constructor is required.

a constructor to instantiate a PopcornOrder for a given variety type and quantity ordered

Methods:

getVariety() - a getter method for the variety field.

getNumOrdered() - returns the number of this variety ordered.

You will then design a MasterList class to keep track of orders that will be as follows:

Instance Variables:

orders - ArrayList of all current popcorn orders (holds PopcornOrder objects)

Constructors

a default constructor that initializes the orders field

no other constructors is required

Methods:

addOrder(PopcornOrder) - adds a PopcornOrder object to orders.

getTotalOrders() - returns the sum of all popcorn unit orders. If there are no popcorn orders in orders this method returns 0.

removeVariety(String) - removes all popcorn orders from orders that are the same variety as the parameter and returns the total number of popcorn units removed. If there are no popcorn orders of that variety this method returns 0. This method assumes that there is only one popcorn order per variety in the list.

toString() - returns a String that contains all popcorn orders in a nicely formatted manner. If there are no orders in orders returns a message stating such.

Your Tasks:

#Part 1 - Implement the classes

Complete the two classes to implement this design. Make sure to use the same identifiers (variables, parameters, method names,) given for testing purposes.

#Part 2 - Test the Implementation

In the main method of the Main class test your implementation:

Create a master list of popcorn orders name popcorn2023.

MasterList popcorn2023 = new MasterList();

Add popcorn orders received so far. It should contain the following PopcornOrders

Variety

Quantity

Butter Microwave

3

Classic Caramel Corn

2

Sea Salt Splash

5

3. Call the toString() and print what it returns to be sure the ArrayList is filled correctly

4. Test the other methods of the MasterList class by using print statements (print() or println()) to check the return values for the following:

popcorn2023.getTotalOrders() returns 10

popcorn2023.removeVariety("Butter Microwave") returns 3

popcorn2023.removeVariety("Cheddar Cheese") returns 0

popcorn2023.getTotalOrders() returns 7

5. Call the toString() again to verify the master list was updated and all Butter Microwave orders have been removed.

6. Create a new ArrayList called popcorn2024 to get ready for next year.

7. Call the following methods to be sure and empty ArrayList will not cause any errors for any of these statements.

popcorn2024.getTotalOrders(); returns 0

popcorn2024.removeVariety("Sea Salt Spalsh"); returns 0

popcorn2024.toString() returns a String stating there are no orders in the master list.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago