Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Feng Liu
committed
Dec 18, 2009
1 parent
e15f004
commit d5dc177
Showing
3 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import model.*; | ||
|
||
import java.io.FileReader; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
public class SystemDatabase { | ||
private HashMap courses; | ||
private HashMap students; | ||
|
||
public SystemDatabase() { | ||
readCourseData(); | ||
readStudentData(); | ||
} | ||
|
||
private void readCourseData() { | ||
try { | ||
BufferedReader fileIn = new BufferedReader(new FileReader("courses.txt")); | ||
String line = fileIn.readLine(); | ||
|
||
while (line != null) { | ||
String[] token = line.split(","); | ||
|
||
String cID = token[0]; | ||
String secID = token[1]; | ||
String prerequisite = token[2]; | ||
String days = token[3]; | ||
int start = Integer.parseInt(token[4]); | ||
int end = Integer.parseInt(token[5]); | ||
|
||
Course aCourse = new Course(cID, secID, prerequisite, days, start, end); | ||
courses.put(cID, aCourse); | ||
|
||
line = fileIn.readLine(); | ||
} | ||
|
||
fileIn.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void readStudentData() { | ||
try { | ||
BufferedReader fileIn = new BufferedReader(new FileReader("courses.txt")); | ||
String line = fileIn.readLine(); | ||
|
||
while (line != null) { | ||
String[] token = line.split(","); | ||
int sID = Integer.parseInt(token[0]); | ||
String name = token[1]; | ||
String courseTaken = token[2]; | ||
Student aStudent = new Student(sID, name, courseTaken); | ||
students.put(new Integer(sID), aStudent); | ||
|
||
line = fileIn.readLine(); | ||
} | ||
|
||
fileIn.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters