I want to make an array of objects, storing variables by referering to array index.
This is what I've written of code so far. Running this will create a NullPointerException
public class Company {
private String owner;
private double income;
public Company(String company)
{
//Unsure whether i need constructor?
}
public void setOwner(String company)
{
owner = company; //Set the value for owner in given arrray object
}
public void setIncome(double income)
{
this.income += income;
}
public String returnOwner()
{
return owner;
}
}
public class Marked {
public static void main(String args[]){
Company[][] owner = new Company[15][20];
owner[0][0].setOwner("CompanyName");
System.out.println("Content of Comapny[" + 0 + "][" + 0 + "] is " + owner[0][0].returnOwner() + " !");
}
}
Any suggestions on what to do next will be much appreciated!
If you're not sure what I'm trying to do, please tell and I will try to explain further.
Thanks for any help in advance