Question: Write the Item class: An Item has a name and a weight which are supplied in the constructor and also have getters. The cost method

Write the Item class: An Item has a name and a weight which are supplied in the constructor and also have getters. The cost method returns the cost of the item which is 2 times the weight. Write the RefrigeratedItem class A RefrigeratedItem also has a name, weight, and temperature which are supplied in the constructor. The temperature has a getter. A RefrigeratedItem has an additional constructor that accepts an Item and a temperature. This constructor is used to convert an Item to a RefrigeratedItem. Hints: The name and weight of this new RefrigeratedItem are inside the Item object. Use this to call the first constructor. The cost of a RefrigeratedItem is 2 times the weight plus: (100-temp)*0.1. For example: if weight=3.0 and temp=10.0, then the cost that is returned is: 15.0 (=2*3.0 + (100-10.0)*0.1). RefrigeratedItem overrides toString to return a string with a format exactly like the example shown below (2 decimal places, $ on cost, etc): name=Ice Cream, cost=$10.00, weight=1.00, temp=20.00 degrees Write the Warehouse class:

Field

Description

items

A protected array of size 10 of Item objects

numItems

The number of items in the array.

Method

Description

Warehouse()

A no-arg constructor that does nothing.

addItem(item:Item)

Adds item to the items in the next available position, provided a position is available.

getItem(i:int):Item

Returns the Item in items at index i, or null if the index is invalid

getItem(name:String):Item

Returns the Item in items with name exactly the same as the argument, or null if it doesnt exist. Hint: loop over the items and look for a name that matches.

getNumItems():int

Returns the number of items in items

getAverageTemp():double

Returns the average temperature of the RefrigeratedItems

getRefrigeratedItems():

RefrigeratedItem[]

Returns an array of the refrigerated items in items. Hint: you will need to count the number of refrigerated items first, in order to create the array to return (see class notes)

getTotalCost():double

Returns the sum of the cost of all the items in items

getTotalCostRefrigerated():double

Returns the sum of the cost of all the RefrigeratedItems in items

removeItem(i:int):Item

Removes and returns the Item in items at index i, or null if the index is invalid.

removeItem(name:String):Item

Removes and returns the Item in items whose name exactly matches the argument, or null if the item was not found.

toString():String

Returns a string with all the items in the array. It should look exactly as shown below. Hint: simply loop over items and call toString on each one:

name=Crackers, cost=$4.50, weight=2.25

name=Apples, cost=$7.00, weight=3.50

name=Ice Cream, cost=$10.00, weight=1.00, temp=20.00 degrees

name=Soda, cost=$3.00, weight=1.50

name=Frozen Veggies, cost=$16.00, weight=3.00, temp=0.05 degrees

...

Write the test methods for the WarehouseTest class that was provided. There, you will write the 13 test methods below.

testAddItem();

testAddItem_Multiple();

testGetItem_WithIndex();

testGetItem_WithName();

testGetAverageTemp();

testGetRefrigeratedItems();

testGetTotalCost();

testGetTotalCostRefrigerated();

testRemoveItem_WithIndex();

testRemoveItem_WithName();

testToString();

IN JAVA

NO ARRAY LIST

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 Databases Questions!