Skip to content

Commit

Permalink
Database initialize.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feng Liu committed Dec 18, 2009
1 parent e15f004 commit d5dc177
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.class
65 changes: 65 additions & 0 deletions SystemDatabase.java
@@ -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();
}
}
}
13 changes: 0 additions & 13 deletions model/Course.java
Expand Up @@ -32,19 +32,6 @@ public Course(String id, String section, String pre, String days, int start, int
this.days = days;
this.start = start;
this.end = end;

/****************
try {
BufferedReader fileIn = new BufferedReader(new FileReader("courses.txt"));
String line = fileIn.readLine();
while (line != null) {
line = fileIn.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
****************/
}

public Vector getPrerequisite() {
Expand Down

0 comments on commit d5dc177

Please sign in to comment.