Hello,
I have this code
public class BulkFoodQ2 extends FoodV5
{
private double unitCost;
public BulkFoodQ2(String brandIn, String productNameIn, String unitsIn, double unitCostIn)
{
super(brandIn, productNameIn, unitsIn);
unitCost = unitCostIn;
}
public void setUnitCost(double unitCostIn)
{
unitCost = unitCostIn;
}
public double getUnitCost()
{
return unitCost;
}
public void setUnitCostToThisUnitCost(FoodV5 anotherFood)
{
double tempUnitCost = anotherFood.getUnitCost();
setUnitCost(tempUnitCost);
}
public double findCost(double amount)
{
return amount * unitCost;
}
}
The class FoodV5 is an abstract, class and I am not understanding how to test the method.
I am trying to test the setUnitCostToThisUnitCost.
I created this:
public class TestBulkFoodQ2
{
public static void main(String[] args)
{
FoodV5[] food = new FoodV5[2];
food[0] = new BulkFoodQ2("Grain", "White Man", "Rice", 10.00);
food[1] = new BulkFoodQ2("Pasta", "Wheatie", "Noodles", 15.00);
for (FoodV5 f : food)
System.out.println(f.getBrand() + ", " + f.getProductName() + ", " + f.getUnits() + ", " + f.getUnitCost());
food.setUnitCostToThisUnitCost(10.00);
System.out.println(food);
}
}
The first part but the method for setUnitCostToThisUnitCost does not work. Any help would be appreciated