posted 13 years ago
Hi everyone, I am running into a problem in a program I am working on. It IS an assignment so I will have to ask that noone give me code that I can just copy and paste. I just need some direction. I am trying to have a student add a course to their file(a text file). I have created a new blank text file(using .createnewfile) for this student and created a file object and scanner for the file with the course. The file(course_list.txt) is as follows:
Course Name, Course Id, Time, Introduction to Philosphy, Phil101, Mon 2:00p-4:00p Wed 9:00a-11:00a Thu 10:00a-12:00p
Introduction to Programming 2, Prog201, Wed 9:00a-11:00a Thu 10:00a-12:00p Fri 1:00p-3:00p
Meaning of Life, Phil411, Mon 9:00a-12:00p Tue 4:00p-7:00p
Introduction to Administrative Studies, Adms101, Tue 12:00p-2:00p Wed 12:00p-2:00p Thu 12:00p-2:00p
end of file
Now I am thinking I should print a numbered list of the courses and use a switch statement to let the user choose which course to add. How I am going to get the numbers(option 1, option 2, etc) in front of the strings, or even get them out of the file as seperate entities, I am not sure. As you can see in the code below(the method at the very bottom), I am familiar with reading text from a file. But now it is getting a but more complex, and I am not sure how to handle it properly.
sample output(preferably without commas as the delimiter):
Course Name, Course Id, Time
1. Introduction to Philosphy, Phil101, Mon 2:00p-4:00p Wed 9:00a-11:00a Thu 10:00a-12:00p
2. Introduction to Programming 2, Prog201, Wed 9:00a-11:00a Thu 10:00a-12:00p Fri 1:00p-3:00p
etc etc.
I also have to make sure the student cannot add a course if the times of day conflict with a course that they have already added.. I guess I could just search the file line by line, assuming everything is on one line. Which it isn't.
Here is the code so far