I have looked up some explanations on the internet but they are all very difficult.
I have a list of items and I'm trying to combine items with the same id to 1 item of that id and the some of the amounts.
in Item :
ArrayList<Item> item = new ArrayList();
public void fuseItems() {
for(Item reference:item) {
for(Item checking:item) {
if(reference.id == checking.id & reference != checking) {
reference.amount+=checking.amount;
item.remove(reference);
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Item here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Item
{
int amount;
String id;
public Item(String newID,int newAmount)
{
id = newID;
amount = newAmount;
}
public Item(String newID)
{
id = newID;
amount = 1;
}
public String toString() {
return "\nItem: id: "+id+"\t amount: "+amount;
}
}

