I have an assignment in blueJ. We have this method for findItem:
public Item findItem(String search) {
for(Item item : items.values()) {
if(item.getName().equalsIgnoreCase(search)) {
return item;
}
}
return null;
}
We are using the if-method to return true and false, but there is something wrong with either the findItem-method or the if-statement. This is the if-statement we have so far:
public void useItem(Item item) {
if (findItem(items) == true) {
System.out.println(getName() + " " + item.getAction() + " " + "a" + " " + item.getName());
}
else {
return false;
}
}
Does anyone know what is wrong with the code? We are also using HashMap for the first time, if that has anything to do with it.
Aucun commentaire:
Enregistrer un commentaire