+5  A: 

I'd probably model the hotel as an object Hotel, the room as an object Room etc. rather than stacking everything together in a multi-tiered collection. That becomes very verbose very quickly, and as soon as you change the relationships then that change is reflected throughout your code.

Each object then contains references to its components (Hotel contains a list of Rooms etc.). Once you do this I think everything should become a lot clearer. Furthermore your Hotel object understands how to find Rooms, the Room objects understand how to get its attributes and your calling code becomes a lot less verbose, and a lot less dependent on the Hotel/Room implementation. e.g. you can do this:

Hotel hotel = new Hotel();
Set<Room> rooms = hotel.getFreeRooms(RoomType.NON_SMOKING);

and so your objects do the work for you (the client) rather than you navigating the object hierarchy and doing the work yourself.

That's the ultimate goal of OO. As soon as I find myself putting together collections of collections, that's often an indicator that a new object class is required.

Brian Agnew
I was writing up an answer very similar to this, beat me to it :) Voting up.
Annie
+3  A: 

You should create proper classes

import java.util.*;

class Hotel {
    public List<Level> levels = new ArrayList<Level>();
}

class Level {
    public List<Room> rooms = new ArrayList<Room>();
}

class Room {
    public Status status = Status.FREE;
    public int counter = 0;
}

enum Status {
    FREE, OCCUPIED
}

and then you use

Hotel hotel = new Hotel();
hotel.levels.add(new Level());
hotel.levels.get(0).rooms.add(new Room());
Room room = hotel.levels.get(0).rooms.get(0);
room.status = Status.OCCUPIED;
room.counter = 8;

et cetera...

 

NB: of course, OO purists will no come and tell you that all these fields need to be private and only be accessed through accessors. But I'd say it's okay if you start with this most simple design and later, as you learn more Java, evolve it to something more complex.

Adrian
I wouldn't say Java purists. Maybe OO purists. I don't think there's anything in the above particular to Java over (say) C++.
Brian Agnew
Your right, fix'd.
Adrian
A: 
class HotelRoom{
     int roomnumber;
     int level;
     boolean reserved;
     int clientCount;

     public int getUniqueNumber(){
       return roomnumber + level*100;
     }
}

...
HotelRoom[][] hotel = new HotelRoom[floorCount][roomCount];

HotelRoom myRoom = hotel[floor][room];
System.out.print("room: " + myRoom.getUniqueNumber());
System.out.print(", Status: " myRoom.reserved);
System.out.print(", Total clients: " myRoom.clientCount);

Your design is pretty crazy, by the way.

Chad Okere
Crazy how ? Can you elucidate ?
Brian Agnew
I just meant using arrays to hold all this stuff, rather then classes.
Chad Okere
A: 

Since level and room number is the key, I would represent room as a value object like this (at a minimum):

class Room {
    public static enum Status {RESERVED, AVAILABLE}

    private Status status;
    private int numberOfPersons;

    // Getters and setters
}

And the key as:

class RoomKey {
    private int levelNumber;
    private int roomNumber;

    public RoomKey(int levelNumber, int roomNumber) {
         this.leveNumber = levelNumber;
         this.roomNumber = roomNumber;
    }
}

And keep the data in a Map like:

Map<RoomKey, Room> rooms = getRoomMap(); 
Room room = rooms.get(new RoomKey(levelNumber, roomNumber))
crunchdog
RoomKey says to me 'the key for the room'.
Brian Agnew
What does the "getRoomMap();" is used for?Maybe insead of getRoomMap() you wanted to say:Map<RoomKey, Room> rooms = new HashMap<RoomKey, Room>();???
Xamas
@Xamas: My thought was that the getRoomMap method not only creates the map but populates it with the data from somewhere, a database for instance.@Brian: To me too. :) Perhaps another name for that class would be more proper, I agree.
crunchdog