Ive tried searching and reading trough (similar sounding) problems, but I cant seem to find a solution.
I am currently making a prototype to control some lamps with a text input. The text input is already working and it can correctly filter trough the inputs and only pick out the relevant parts.
Anyway, for that to be usefull now I need to first create Objects of my House, which contain all floors, which contain all rooms, which contains all actors(Lamps etc.).
These are the snippets for all those Objects, from top to bottom as theyre supposed to be stacke inside eachother(The code isnt finished yet nor optimized, I know I can use switch-case for all the if-else statements):
import java.util.ArrayList;
public class Building {
String Name;
ArrayList<floor> floor = new ArrayList<floor>();
public Building(String Name){
this.Name = Name;
}
public boolean checkFloor(String Name){
int count = floor.size();
boolean ret = false;
while(count < floor.size()){
if (floor.get(count).Name == Name){
count = floor.size();
ret = true;
}
count++;
}
return(ret);
}
public void newFloor(String Name){
Name = Name.toLowerCase();
if (Name == "keller" || Name == "basement"){
floor basement = new floor("basement");
floor.add(basement);
}
else if (Name == "eg"){
floor ground = new floor("eg");
floor.add(ground);
}
else if (Name == "1og"){
floor first = new floor("first");
floor.add(first);
}
else if (Name == "2og"){
floor second = new floor("second");
floor.add(second);
}
else if (Name == "3og"){
floor third = new floor("third");
floor.add(third);
}
}
public void newRoom(String Floor, String Name){
}
}
public class floor {
String Name;
ArrayList<room> room = new ArrayList<room>();
transcoder transcode = new transcoder();
public floor(String Name){
this.Name = Name;
}
public boolean checkRoom(String Name){
int count = room.size();
boolean ret = false;
while(count < room.size()){
if (room.get(count).Name == Name){
count = room.size();
ret = true;
}
count++;
}
return(ret);
}
public void newRoom(String mName){
String Name = transcode.getRoom(mName);
if( Name == "ground"){
room ground = new room("ground");
room.add(ground);
}
else if ( Name == "basement"){
room basement = new room("basement");
room.add(basement);
}
else if ( Name == "first"){
room first = new room("first");
room.add(first);
}
else if ( Name == "second"){
room second = new room("second");
room.add(second);
}
}
}
public class room {
String Name;
ArrayList<Actor> Actors = new ArrayList<Actor>();
public room(String Name){
this.Name = Name;
}
public void addActor(String Name, int Type, String Address, int Channel, boolean Dim){
Actors.add(new Actor(Name, Type, Address, Channel, Dim));
}
public void removeActor(String Name){
int count = 0;
while (count <= Actors.size()){
if (Actors.get(count).Name == Name){
Actors.remove(count);
count = Actors.size();
}
count++;
}
}
public boolean containsActor(String Name){
int count = 0;
boolean ret = false;
while (count < Actors.size()){
if (Actors.get(count).Name == Name){
ret = true;
count = Actors.size();
}
count++;
}
return(ret);
}
public String getAddress(String Name){
int count = 0;
String ret = "leer";
while (count < Actors.size()){
if (Actors.get(count).Name == Name){
ret = Actors.get(count).Address;
count = Actors.size();
}
count++;
}
return(ret);
}
public int getType(String Name){
int count = 0;
int ret = 0;
while (count < Actors.size()){
if (Actors.get(count).Name == Name){
ret = Actors.get(count).Type;
count = Actors.size();
}
count++;
}
return(ret);
}
}
public class Actor {
String Name;
String Address;
int Channel;
int Type;
boolean Dim;
int On; //muss noch deklariert werden!
int Off;
public Actor(String Name, int Type, String Address, int Channel, boolean Dim){
this.Name = Name;
this.Type = Type;
this.Address = Address;
this.Channel = Channel;
this.Dim = Dim;
}
}
What I am trying to do now in my Mainclass, is to create a new Building with a floor, room and some actors. The code goes as follow:
System.out.println("Gebäudename eingeben(egal): ");
String Name = user_input.nextLine();
Building Building = new Building(Name);
System.out.println("Stockname eingeben(eg): ");
Name = user_input.nextLine();
Building.newFloor(Name);
System.out.println("Raumname eingeben(wohnen): ");
Name = user_input.nextLine();
Building.floor
Now at the end at Building.floor, I dont quite see how I can now add a new Room to the object floor. Id appreciate any help, as Im not quite that fancy with Java yet and probably am missing an obvious part.