Building construction with array list in java -


i beginer developer , have java program array list. program building constructor in must create entrances , floors , apartments in array list , program has work user iputs using console. , example if want create apartment on 10th floor there 9 floors has give me error message. did here part of code:

public class building {     static string answer;  public static void main(string[] args) {     // todo code application logic here     scanner input = new scanner(system.in);      list<entrance> entrance = new arraylist<entrance>();     list<floors> floor = new arraylist<floors>();     list<apart> apartment = new arraylist<apart>();      system.out.println("welcome, choose (a) operations , (b) information!");     answer = input.nextline();      if(answer.equals("a")){         system.out.println("chose (a) create entrance , (b) create floor , (v) create apartment");         answer = input.nextline();          if(answer.equals("a")){               system.out.println("creating entrance...");              entrance entrancea = new entrance();              entrance.add(entrancea);               system.out.println("create name of entrance:");             entrancea.setnameentrance(input.nextline());               system.out.println("how many floors in part of building:");             entrancea.setnumberfloors(input.nextint());                   }           }else if(answer.equals("b")){              system.out.println("creating floor...");              floors floora = new floors();             floor.add(floora);              system.out.println("how many aparments on floor:");             floora.setnumberapart(input.nextint());            }   } 

i think in terms of design can change bit. example can pull out entrance, floor,apart class called structure or building.

you can use called composition in object oriented terms, means have class called building , contains fields window, doors etc (has relationship)

so basically:

class building {

public building(list<entrance> entrance, list<floors> floors, list<apart> apart) list<entrance> entrance; list<floors> floors; list<apart> apart; } 

but why not have each floor can have apart objects.

so class:

class floor { list<apart> apart; public void addapartmentwithnewowner(string owner,mortgage mortgage) {    etc. etc. } 

this makes more sense because can build floors in building.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -