Forgive me, I am new to Java! and is for a university project, I am having trouble with a few concepts, I have tried to google around to no avail!. How can I instantiate a certain amount of heaters of the heater class, inside the MarsRoom class, and then access them in the main of the MasterControlPanel. But depending on the number of numheaters set in the constructor??. I have tried this but its not recognising the object room1.roomheaters[0]. It does however recognise it if I just instantiate one object like Heaters roomheaters = new Heaters();. Many thanks
public class MasterControlPanel{
public static void main(String[] args){
MarsRoom room1 = new MarsRoom(40, 40, 20, 20, 8, 2, 4);
MarsRoom room2 = new MarsRoom(40, 40, 20, 20, 8, 2, 4);
MarsRoom room3 = new MarsRoom(40, 40, 20, 20, 8, 2, 4);
MarsRoom room4 = new MarsRoom(40, 40, 20, 20, 8, 2, 4);
room1.createheaters();
System.out.println("Turned " + (room1.roomheaters[0].getHeater() ? " ON" : " OFF"));
}
}
public class MarsRoom extends Rooms implements RoomInterface{
int roomareasq;
int heatloss;
float insideTemp;
float outsideTemp;
float uvalue;
int numheaters;
int numlights;
Heaters roomheaters[] = new Heaters[numheaters];
public MarsRoom(){
}
public MarsRoom(int windowsH, int windowsW, int wallsH, int wallsW, int windowC, int heaters, int lights){
windowsHeight = windowsH;
windowsWidth = windowsW;
wallsHeight = wallsH;
wallsWidth = wallsW;
windowCeiling = windowC;
numheaters = heaters;
numlights = lights;
}
public void createheaters(){
for (int i=0; i < numheaters; i++)
{
roomheaters[i] = new Heaters();
}
}
public void calculateheatloss(){
}
}
roomheatersdeclared?