Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi. I have class of Item, RefrigeratedItem, and Warehouse class. I am stuck at writing the code to testGetRefrigeratedItems(),testGetTotalCostRefrigerated(), testRemoveItem_WithIndex()testRemoveItem_WithName(); in Warehouse class. Please help.

Hi. I have class of Item, RefrigeratedItem, and Warehouse class. I am stuck at writing the code to "testGetRefrigeratedItems()",testGetTotalCostRefrigerated(), testRemoveItem_WithIndex()testRemoveItem_WithName(); in Warehouse class. Please help. Thank you

-------------------------

package prob1;

public class Item { protected String name; protected double weight; public Item(String name, double weight) { this.name = name; this.weight = weight; } // method public String getName() { return name; } public double getWeight() { return weight; } public double cost() { return 2*weight; public String toString() { String msg = String.format("name=%s, cost=$%.2f, weight=%.2f", name, cost(), weight); return msg; } -----------------------------------------

package prob1;

public class RefrigeratedItem extends Item { //instance variable protected double temp; public RefrigeratedItem (String name, double weight, double temp) { super(name, weight); this.temp = temp; } public RefrigeratedItem(Item item, double temp) { super(item.getName(), item.getWeight()); this.temp=temp; public double cost() { return (2*weight + (100-temp)*0.1); } public double getTemp() { return temp; } @Override public String toString() { return super.toString()+" temp="+ temp + " degrees"; }

} -------------------------------------------

package prob1;

public class Warehouse { private int numItems = 0; protected Item []items = new Item[10] public Warehouse() { } // methods public int getNumitems() { return numItems; } public void addItem(Item item) { if(numItems< items.length) { items[numItems++] = item; } } public Item getItem(int i) { if(i>=0 && i < numItems) { return items[i]; } return null; } public Item getItem(String name) { for(int i = 0; i

}

--------------------------------

package prob1;

public class WarehouseTest {

public static void main(String[] args) { // testGetRefrigeratedItems(); // testGetTotalCost(); // testGetTotalCostRefrigerated(); // testRemoveItem_WithIndex(); // testRemoveItem_WithName(); // testToString(); } // /** // * Add 5 items, 3 of which are refrigerated. Verify that the 3 are returned in array. // */ // public static void testGetRefrigeratedItems() { // System.out.println("-->testGetRefrigeratedItems"); // System.out.println("NOT IMPLEMENTED"); // } // // /** // * Add 5 items, 3 of which are refrigerated. Verify the total cost. // */ // public static void testGetTotalCost() { // System.out.println("-->testGetTotalCostRefrigerated"); // System.out.println("NOT IMPLEMENTED"); // } // // /** // * Add 5 items, 3 of which are refrigerated. Verify the total cost of the 3 refrigerated items // */ // public static void testGetTotalCostRefrigerated() { // System.out.println("-->testGetTotalCostRefrigerated"); // System.out.println("NOT IMPLEMENTED"); // } // // /** // * Add 5 items, 3 of which are refrigerated. Remove the one at position 2 and // * verify: the item is returned, and the number of items is decremented. // */ // public static void testRemoveItem_WithIndex() { // System.out.println("-->testRemoveItem_WithIndex"); // System.out.println("NOT IMPLEMENTED"); // } // // /** // * Add 5 items, 3 of which are refrigerated. Remove one with a name that exists and // * verify: the item is returned, and the number of items is decremented. // */ // public static void testRemoveItem_WithName() { // System.out.println("-->testRemoveItem_WithName"); // System.out.println("NOT IMPLEMENTED"); // } // // /** // * Verify that the toString method produces a string exactly // * as specified in the assignment document. // */ // public static void testToString() { // System.out.println("-->testToString"); // System.out.println("NOT IMPLEMENTED"); // } //helper methods public static Warehouse WarehouseThreItems() { Warehouse threeItems = new Warehouse(); Item item = new Item ("pork", 50.00); Item item2 = new Item ("chicken", 45.25); RefrigeratedItem item3 = new RefrigeratedItem("fish", 25.25, 10.50); threeItems.addItem(item); threeItems.addItem(item2); threeItems.addItem(item3); return threeItems; } public static Warehouse WarehouseFiveItems() { Warehouse fiveItems = new Warehouse(); Item item = new Item ("pork", 50.00); Item item2 = new Item ("chicken", 45.25); RefrigeratedItem item3 = new RefrigeratedItem("fish", 25.25, 10.50); RefrigeratedItem item4 = new RefrigeratedItem("Ice-Cream", 2.50, 15); RefrigeratedItem item5 = new RefrigeratedItem(item, 25.25); fiveItems.addItem(item); fiveItems.addItem(item2); fiveItems.addItem(item3); fiveItems.addItem(item4); fiveItems.addItem(item5); return fiveItems; } public double getAvarageTemp() { double avarageTemp = 0.00; for(int i=0; i

}

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

Students also viewed these Databases questions

Question

How can the Internet be helpful in a job search? (Objective 2)

Answered: 1 week ago

Question

5. Have you any experience with agile software development?

Answered: 1 week ago