Im learning to make a game, and im nearly done with the main part, but cant get one thing working.
I need to generate some fields from Field.java
The Code from Field.java is the following
package matedor;
class Field{
private String name;
private int number;
public Field (String fieldname, int fieldnumber){
this.name = fieldname;
this.number= fieldnumber;
}
public String getFieldname(){
return name;
}
public int getFieldnumber(){
return number;
}
public String toString(){
return number+name;
}
public boolean equals(Object obj){
Field field = (Field) obj;
return (number == field.number && name.equals(field.name));
}
}
In my main i need to generate the following which is not editable:
fieldname1, fieldname2.....to fieldname40
I know i have to do it with an ArrayList, and i want to create 40 instances of the field, so i have from fieldname1 to fieldname40. How do i do that?
In my main i have tried to do the following, but i get the null statement
Field[] felterISpil=new Field[40];
System.out.println(Arrays.toString(felterISpil));
Output:
[null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]