part of my programm:
public class Backpack {
private int maxamount, maxweight;
public Backpack(int ma, int mw){
setMaxamount(ma);
setMaxweight(mw);
}
public void setMaxamount(int ma){
this.maxamount=ma;
}
public void setMaxweight(int mw){
this.maxweight=mw;
}
Item IA[]=new Item[maxamount];
int weightA[]=new int[maxamount];
String nameA[]=new String[maxamount];
public char addItem(Item I){
...
When I use this the variable "maxamount" has no value and I can't store values in the array, but when I'm using this:
public class Backpack {
private int maxamount, maxweight;
public Backpack(int ma, int mw){
setMaxamount(ma);
setMaxweight(mw);
}
public void setMaxamount(int ma){
this.maxamount=ma;
}
public void setMaxweight(int mw){
this.maxweight=mw;
}
public char addItem(Item I){
Item IA[]=new Item[maxamount];
int weightA[]=new int[maxamount];
String nameA[]=new String[maxamount];
...
,"maxamount" has the value it's supposed to have(from another class), but I need the arrays and the values stored in them in other methods too. So how can I initialize the Arrays out of the method so I can use them for every method?