Ski Hotel

The OHS school is planning a ski trip for 40 students.

The HOTEL for the ski-trip has 4 beds in each room. 
A list of STUDENTS must be assigned to each room.

For example:

   STUDENTS      HOTEL------------------------------
     aaa         | 0    aaa   eee   iii     empty
     bbb         | 1    bbb   fff   jjj     empty
     ccc         | 2    ccc   ggg   empty   empty
     ddd         | 3    ddd   hhh   empty   empty
     eee         |----------------------------------
     fff
     ggg
     hhh
     iii
     jjj

In this example there are 6 empty beds.


The program below assigns single students to beds.  

(1) Run this program.  Assign a few students to beds.

(2) Find out what is defective in this program - specifically, explain
    why it CANNOT assign students as shown above.

(3) Fix the program so that it can be used to assign beds correctly.

(4) Change the program so that it is ONLY POSSIBLE to assign a student
    to an empty bed.

(5) Add a new method called ROOMMATES.  It inputs the name of a
    student, searches for that student, and prints the names
    of the other students in the same room.

(6)  The program should automatically assign a room, according to this algorithm:

   Copy all the room numbers from ROOMS into the first column of HOTEL
   Count down the first column, placing a student in each room.
   Go back to the top of the list, and count down the second column
       placing a student in each room.
   Continue through the third and fourth columns.

Change the program so that it AUTOMATICALLY assigns rooms as described above.    


You will need to download TWO java files
including the SkiHotel program AND the GUI Library:

     SkiHotel.java
       GUI.java

Below is the listing of the main program:




import java.awt.*;

public class SkiHotel extends GUI
{  
   Button bInputStudent = addButton("Input Student",50,50,150,50,this);
   Button bShowRooms = addButton("Show Rooms",200,50,150,50,this);
  
   String[][] hotel = new String[10][4];
         // 10 rooms, each with 8 beds
     
   public SkiHotel()
   {
      super(600,400);
      initialize();
   }
  
   public void actions(Object source, String command)
   {
      if (source == bInputStudent)
      {  inputStudent(); }
      else if (source == bShowRooms)
      {  showRooms(); }        
   }
  
   public void initialize()
   {
      for(int r = 0; r < 10; r = r+1)
      { 
         for (int b = 0; b < 4; b = b+1)
         {
            hotel[r][b] = "---";     // empty bed
         }
      }
   }
  
   public void inputStudent()
   {
      String name = input("Name?");
      int room = inputInt("Room (1-10)?");
      room = room - 1;
      if (hotel[room][0].equals("---") )
      {  hotel[room][0] = name; }
     
   }
  
   public void showRooms()
   {
      String all = "";
      for (int r = 0; r < 10; r = r+1)
      {  String beds = "room " + (r+1);
         for (int b = 0; b < 4; b = b+1)
         { 
            beds = beds + "   " + hotel[r][b];
         }
         all = all + beds + "\n";
      }
      output(all);
   }
  
   public static void main(String[] args)
   {  new SkiHotel(); }

}