This is where I am trying to add isCompatibleWith() from the class Fruit into a class called ShoppingCard and specifcaly addFruit within it.
public boolean addFruit(String fruitName,int type, int numItems, int itemWeight) {
if (toCapacity() == false)
{
if (Fruit.isCompatibleWith() == true) //This line does not work.
{
return true;
}
else
System.out.println("Cannot add fruit, incompatible with other fruits.");
}
else
System.out.println("Cannot add fruit, cart is full.");
return false;}
Fruit.java
public boolean isCompatibleWith(Fruit other) {
if (!this.isPerishable() && !other.isPerishable()) // both are non perishable
return true;
if (this.isPerishable() != other.isPerishable()) // one is perishable, the other is not
return false;
if (this.getType() == other.getType()) // if you've gotten here, both are perishable
return true;
return false;
}