Question: Java Software Problem Help -Step 1: 1. Write anabstractclass Product that has the followingprivatefields: An integer id A string description A double price 2. Add

Java Software Problem Help

-Step 1:

1. Write anabstractclass Product that has the followingprivatefields:

An integer id A string description A double price

2. Add aparameterizedconstructor that accepts and sets all data. All of the parameters should have the same identifier (i.e. id, description and price) as the class level data. DoNOTadd a default constructor to this class.

3. Add getters and setters for all the fields.

4. Add a toString method that prints the Product dataformattedas:

ID: 101 Description: Cheese Pizza Price: $6.00

To format as currency use:

// Create an instance of a NumberFormatter for currency NumberFormat formatter = NumberFormat.getCurrencyInstance();

// Format the double - returns a string with format currency formatter.format(price)

-Step 2

1. Write afinalclass Pizza that inherits the Product class and has the following data asprivate fields:

A string type A string size (small, medium or large)

2. Add aparameterizedconstructor that accepts and sets all data.

3. Add getters and setters for all the fields.

4. Add a toString method that prints the Product dataformattedas:

Get toString from Product Type: Pepperoni Pizza Size: Medium

-Step 3

1. Write afinalclass Soda that inherits the Product class and has the following data asprivatefields:

A string Flavor A int Size (in ounces)

2. Add aparameterizedconstructor that accepts and sets all data.

3. Add getters and setters for all the fields.

4. Add a toString method that prints the Product dataformattedas:

Get toString from Product Flavor: Cola Size: 16 ounces

-Step 4:

1. Write a class ProductList thatinheritsan ArrayList of Product.

2.Overridethe Object toString to print all the Products in the ArrayList using their respective toString methods.

3. Write a method calledsumthatcalculatesandreturnsthesumof all prices of Products in the list.

Step 4:

1. Add code to the main method to instantiateat least twoPizza andat least twoSoda.

2. Create an array of Product, copy the Pizzas and Sodas from step 1 to the array. Use a loop to print the array to screen. The screen output should look like:

ID: 1 Description: Pizza Price: $6.00 Type: Cheese Size: Small

ID: 2 Description: Pizza Price: $11.00 Type: Pepporoni Size: Large

ID: 3 Description: Soda Price: $2.00 Flavor: Cola Size: 16 ounces

ID: 4 Description: Soda Price: $1.50 Flavor: Limon Size: 12 ounces

3. Create an instance of a ProductList, add the Pizzas and Sodas from step 1 to the ProductList. Use aforeachloop to print the ProductList to screen. The screen output should look the same as the array in step 2.

4. Print the sum of prices for the Products in the ProductList to screen as:

The sum of prices is: $20.50

Use a NumberFormatter to format as currency.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!