import javax.swing.JOptionPane;
import java.util.ArrayList;
/**
 * A driver to test the psychology experiment scheduler.
 * 
 * @author CS1 Spring 2006
 * @version 1.5
 */
public class ScheduleTester {

  /** Exercise the Schedule class. */
  public static void main(String[] args) {
    Schedule sched = new Schedule();
    // Check computation of number of sessions
    String input = JOptionPane.showInputDialog(
                     "Please enter the number of students.");
    int numStudents = Integer.parseInt(input);
    JOptionPane.showMessageDialog(null,
                                  numStudents
                                  + " students will require "
                                  + sched.numSessions(numStudents)
                                  + " sessions.");
    // Check computation of number of trainers
    input = JOptionPane.showInputDialog(
              "How many training periods do you have?");
    int numPeriods = Integer.parseInt(input);
    JOptionPane.showMessageDialog(null,
                                  "You can train "
                                  + sched.numTrainers(numPeriods)
                                  + " experimenters in "
                                  + numPeriods
                                  + " periods.");
    // Check computation of number of periods
    input = JOptionPane.showInputDialog(
              "How many experimenters do you need to train?");
    int numExperimenters = Integer.parseInt(input);
    JOptionPane.showMessageDialog(null,
                                  "It will take "
                                  + sched.numPeriods(numExperimenters)
                                  + " periods to get at least "
                                  + numExperimenters
                                  + " trained experimenters.");
    // Check adding rooms to a room list.
    ArrayList<Room> roomList = addRooms();
    String roomDisplayString = "";
    for (Room r : roomList) {
      roomDisplayString += r.getBuilding() + " " + r.getRoomNumber() + "\n";
    }
    JOptionPane.showMessageDialog(null,
                                  "ROOMS ENTERED:\n"
                                  + roomDisplayString);
  }

  /**
   * Create a list of rooms with information entered by the user
   * at the console.
   * @return list of rooms
   */
  public static ArrayList<Room> addRooms() {
    String building = JOptionPane.showInputDialog(
              "Please enter the name of the next room's building or choose Cancel");
    if (building == null) {
        return new ArrayList<Room>();
    }
    String roomNumber = JOptionPane.showInputDialog(
              "Please enter the room number");
    Room newRoom = new Room(building, roomNumber);
    ArrayList<Room> theRooms = addRooms();
    theRooms.add(0, newRoom);
    return theRooms;
  }
}
