Jayesh A Lalwani wrote:I would suggest that you break down the problem into 3 parts a) Reading the student.txt file and loading it into a data structure in memory b) Reading the course. txt file and loading in into a data structure in memory c) merging the 2 inputs to get the output that you need. These are your 3 high level modules.
Next start thinking about what those input and output data structures will look like and how you would merge them. This will guide you towards defining the interface between the modules
Once you have the interfaces designed, work on one module at a time, test them independently, then hook them up and test them all together
As a general guideline, programming is an exercise in breaking down problems into manageable pieces. Don't try to solve the entire problem at once. At any time, a problem starts to overwhelm you, start thinking about how you can break it down into independent manageable pieces. Any problem is solvable as long as you break it down.
Winston Gutkowski wrote:
stefan balling wrote:So, my idea was to run through the course file first and take the course name off and pass the remain info into the timeslot class and play around with it there. Then run through the student file and take the student ID into the student class and pass the rest again into timeslot. The problem is I dont know how to seperate the two files when I pass them into the timeslot. I wanted to add a boolean value to determine which one is being passed in but I was told I can't do that. Can anyone give me some guidance? I don't want answers just a step in the right direction!
OK, well firstly, I'd follow Campbell's advice and play around before you start ANY coding. And don't forget to write out your findings in English.
Secondly, I'd split the problem into two major phases:
1. Load the data.
2. Validate it.
In the first phase, don't worry about whether things are correct or not, simply convert all those 'orrible Strings into proper Java objects.
Third, I'd probably add a Day class (or, probably even better, an enum) to the ones you've already got.
Basically, Strings make bad substitutes for other types, so you want to convert as many of them as you can as fast as you can.
However, I do have a question:
The course file contains a LabGroup AND a TimeSlot, but no indication as to whether the two are related or not.
For example: is LabGroup 'H' always associated with the TimeSlot 'Mon 13:00 15:00' - with or without the 'Mon' - or is it simply the designation for a lab room which could be used with any (presumably non-overlapping) TimeSlot?
My suspicion is the latter, but it's something that would be worth finding out before you get too far down the road.
Winston
Jelle Klap wrote:Hi, and welcome to the Ranch!
I've take the liberty to add quote-tags to the section of your post to make it clear that this is the actual worksheet text.
stefan balling wrote:The problem is I dont know how to seperate the two files when I pass them into the timeslot. I wanted to add a boolean value to determine which one is being passed in but I was told I can't do that.
I don't quite follow what you mean by this, could you elaborate?
Maybe you could describe to us in pseudocode the steps you think the program should take?
Course worksheet wrote:
The purpose of the program is to determine students’ eligibility and availability for lab groups for a given course. The program is to read data from two input files, one containing details of a course and the other details of students.
The Course file
The first line of the file course.txt contains the course name, which may contain embedded spaces, for example
Java Programming 2
Each subsequent line of the file contains information on a laboratory group associated with the course. A typical line has the form
H Mon 13:00 15:00
where the first item is the lab group label (a single character), and the other three items give the time slot for that lab group.
The student file
Each line of the file students.txt contains a student number followed by a sequence of time slots, representing the existing commitments of the student, for example
0903612 Mon 12:00 14:00 Tue 14:00 16:00 Wed 09:00 11:00 Wed 14:00 16:00 Thur 12:00 13:00 Fri 10:00 12:00
(Note that this represents a single line of the file.)
The program
The program is to read the data from the two files and write to standard output the name of the course, followed by one line for each student. This line should contain the student number, an indication of whether the student is eligible for the course, and if so a list of the lab groups for which s/he is available. A student is eligible for the course if at least one of the lab group time slots does not overlap any of his/her commitments, and is available for each of the lab groups with a scheduled time slot that does not overlap any of those commitments1. So the first three lines of output might be:
Java Programming 2
0903612 ineligible
0951411 eligible A C F
You are given a complete class CheckStudents containing a main program that is designed to solve this problem. However, a number of other classes are required to complete the solution.
Task 1. You are given a complete class Time to represent a time in hours and minutes, and a skeleton class TimeSlot to represent a time slot consisting of a day, a start time and a finish time. You are to complete the implementation of this TimeSlot class.
In the TimeSlot class, you should provide a full set of constructors, accessors and mutators, together with equals and toString methods, and any other methods that may be appropriate for the context. In the other classes, you need give only methods that are actually used in your program.
Task 2. You are given a skeleton of a class LabGroup to represent a lab group. You are to complete the implementation of this class.
Task 3. You are given a skeleton of a class Course to represent a course, which involves an unknown number of lab groups. You are to complete the implementation of this class. It is suggested that the class should use an ArrayList to hold the lab groups for the course.
Task 4. You are given a skeleton of a class Student to represent a student, to include information on the student’s commitments and other attributes relevant to the context. You are to complete the implementation of this class.
Notes
1. The program assumes that the input files are in exactly the right format.
2. Each class is to include a constructor that creates an object by reading from a scanner, tailored for the context. This will be the only constructor that is needed in the LabGroup, Course and Student classes. The given Time class has such a constructor2.
3. You should not make any changes to the classes Time or CheckStudents.
4. Some of the methods required in the classes that you have to implement are immediately apparent from inspection of the main program. Others you will have to discover for yourself.
5. You may assume that the days are represented as Mon, Tue, Wed, Thur and Fri (no labs take place at the weekend!)