Computer Science 210 Lab 6: Introduction to Scheduling
Due:
Nov. 2
Objectives and Overview: Scheduling is
one of the most important areas of application for computer science.
The goal of this lab is to provide an introduction to the topic (which
we will continue with in future labs) and to give you more experience
designing your own data structures. For instance, if we were to
have oral examinations in this class then it would be necessary to
schedule each student for a time slot. One way to do this is to
collect the times when different students would be available.
Doing the actual scheduling would require building a data structure which
represents this information in some efficient way. When you are
done with this lab you should have a program that reads schedule
information from a file, creates a data structure based upon that
information, and prints out an organized representation of the
information.
Part 1 - The Schedule File
In the course material folder there is a new file called "schedule."
Its format is as follows: The first line is an integer which
represents the number of time slots. This is followed by one
line for each time slot. After that are lines for each of
the students in the class and their choices of time slots. The
idea is that a scheduling program would read this information in,
create a data structure to handle it efficiently and then assign
each student a time slot. Your program will handle all but
the scheduling (we will do that in a future lab).
Here is the problem. We want to write a program that develops
and displays a list of the actual time slots, and with each time slot,
the first names of all students who selected it. For instance, if Ay,
Sara, and Erika selected time slot 9:00, then the display should include
the following line:
9:00 Ay Sara Erika
Since each time slot is a string, as is the first name of each student,
we can see that the StringList is an appropriate data structre
for storing the names of time slots and students efficiently. Moreover,
since the number of students selecting different time slots will vary widely,
a very flexible data structure is required. Here is a linked list of strings
that represents the above sample information.
Now we need to develop this information for all the time slots, not
just 9:00. This suggests a Vector of lists, each one beginning with
a different time slot. The above list would appear in the 2nd entry
in that Vector for the data file schedule, preceded by a list
for the time slot 8:30 and followed by a list for the time slot 9:30.
Part 2 - The data structure
The scheduling program will need to have the information
organized according to the time slots. Then, for each
timeslot the necessary information is just a list of students
who have chosen that slot. Since you know exactly how many
time slots there are, and the scheduler might access them
in a number of different ways, a sensible data structure
would consist of a Vector of Lists, where each element of
the Vector is the information associated with one timeslot.
The public methods of this new class (called "StringList"
should include:
StringList(int n) - constructor creates a new StringList
variable, initializing the storage Vector to the proper size
insert(String s, int slot) - inserts a new String s at the
end of the linked list in the n'th slot of the Vector
display(int n) - displays the strings in all the individual
nodes in the list in slot n.
display() - displays the entire data structure.
length(int n) - returns the length (number of nodes) of the
list in the n'th slot
length() - returns the size of the Vector
Part 3 - Use the StringList Class
Armed with your StringList class, you should write a program
which reads in the "schedule" file, puts it into the StringList
data structure and then displays the entire data structure.
Lab 4 Deliverables:
Put your project folder into the drop box with the usual naming
conventions. Also hand in hardcopy listings of the programs,
as well as a listing of the program output.