/* * Rooms.java * * Created on April 24, 2008, 5:29 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package rooms; /** * * @author Andrew */ public class Rooms { int numSmoking; int numNonSmoking; boolean occupied[]; /** Creates a new instance of Rooms */ public Rooms(int non, int sm) { occupied = new boolean [sm+non]; for(int i = 0; i < (sm+non); i++) occupied[i] = false; numSmoking = sm; numNonSmoking = non; } //end of Rooms constructor public int bookRoom (boolean smoking) { int begin, end, roomNumber = 0; if (!smoking) { begin = 0; end = numNonSmoking; } //end true for not smoking else { begin = numNonSmoking; end = numSmoking + numNonSmoking; } //end false for(int i = begin; i < end; ++i) { if(!occupied[i]) { occupied[i] = true; roomNumber = i+ 1; i = end; } //end true for not occupied } //end for return roomNumber; } //end bookRoom method } //end of class Rooms