Campbell Ritchie wrote:I think the time has come to turn yout computer off and write down what you are trying to do on paper. Only when you have that worked out will you be able to write any code.
Paul Clapham wrote:I understand the "capacity" of a hotel -- it's the maximum number of people who can stay in the hotel at one time. That's what "capacity" means. But "size"? I don't understand what the "size" of a hotel is. Perhaps you could explain? Yes, I realize that having to work in English makes that sort of thing harder... perhaps you thought of a specific word in French (which it looks to me is your native language) but your English translation as "size" is not at all specific.
And don't be afraid of long variable names: if you want a variable to store the number of available rooms then numberOfAvailableRooms is a good choice for that variable's name.
Les Morgan wrote:Since you are using synchronized in your methods, I suggest you change your declaration of numberOfOccupatedRooms to a protected static int. This will make it a class variable and tie any and all threads to one instance of numberOfOccupatedRooms. As it stands now in your code, the use of a protected int is an instance variable. Instance variables will tie to any particular instance, so if you have 2 instances running, then your number of occupied rooms will be tracked separately in each instance and allow maximum checkins in each instance, 250 in the first instance and 250 more in each additional instance. Without the use of a static qualifier, Class Variable, you will be able to double, triple, or more book your rooms according to how many instances you have running.
Campbell Ritchie wrote:I worry whenever I see anything marked static. Making the variable static would suggest every hotel has the same number of rooms. Are you sure about that? Should the exercise use one instance reached by several threads? Is this possible in view of the tight specifications above?