I have created another class called Item that has the parameters description (string) and price (int). In a separate class, called Seller, Item is used to save a list of items to the specific seller. Everything runs without error, but the values returned is what is throwing me off.
One method adds the items to the ArrayList, and another removes an item once it is "sold". A third method adds the item that was just removed back to the arraylist.
I have two questions,
1.What should be returned in sellItem if what should be there is just the item that was removed (sold).
2.How would I add the item back in when the only parameter is the returned value from above (not description or price). In the tested code, i = s.sellItem("one-bedroom condo");
is given along with s.acceptReturnedItem(i);
so that the parameter is the variable used previously.
Here is my code:
ArrayList <Item> items = new ArrayList <Item>();
public void addItem(String description, int price) {
Item i = new Item(description, price);
items.add(i);
return;
}
//adds item with two parameters
public Item sellItem(String description) {
for (Item v: items) {
if (v.getDescription() == description) {
items.remove(v);
}
}
return new Item(?); //what are we returning???
}
public Item acceptReturnedItem(Item x) { //where x is the returned item from above
//Item f = new Item(addItem); not sure if this is correct
//items.add(f); would add it??
return new Item(?);
}