Question..
I'm importing a text file with information regarding student information. The code below works perfectly when importing the contents of that text file. The text file contains several lines of information including the student's name, the number of courses he or she is registered for, and the course name and its number level.
For instance, a piece of the text file may read:
John H Doe<== Student Name
3 <== Number of courses currently registered for
MATH 250 3<== Math course with level 250 and worth 3 credit hours
MATH 117 3<== Another math course with level 117 and worth 3 credit hours
ENGL 201 3<== English course with level 201 and worth 3 credit hours
The code that I've come up with below takes the course names, course level, and credit hours and reads them as a String, int, and another int value, respectively, and stores them as variables. I need to sort these first by course name and then by course level. I'm smelling some nested if's with some nested sorts but I am at a standstill.
What would be an easy way to do this? I'm sure I can sort the course names without a problem, but how can I sort the course numbers? Would I use some sort of nested sort? And if so, how would I know I'm sorting the course levels for the two MATH courses and not including the course level for the ENGL class?
Also, note that in
and out
are part of an in-house utility, so not to confuse anyone. :-)
This portion of code is executing and loops through the text file reading the various data. I've omitted the rest of the code.
while (!in.eof()){
in.readWord();
String firstName = in.lastString();
System.out.println("First Name: " +firstName);
in.readWord();
String middleInitial = in.lastString();
System.out.println("Middle Initial: " +middleInitial);
in.readWord();
String lastName = in.lastString();
System.out.println("Last Name: " +lastName);
in.readLine();
in.readInt();
int numCourses = in.lastInt();
System.out.println("Number of Registered Courses: " +numCourses);
in.readLine();
for (int i = 1; i <= numCourses; i++){
in.readWord();
String courseName = in.lastString();
System.out.println("Course Name: " +courseName);
in.readInt();
int courseNum = in.lastInt();
System.out.println("Course Num: " +courseNum);
in.readInt();
int creditHours = in.lastInt();
System.out.println("Credit Hours: " +creditHours);
in.readLine();
}
out.blankLine(1);
}

