Skip to content

Commit

Permalink
Added Scheduler.java (contains generate courses method)
Browse files Browse the repository at this point in the history
  • Loading branch information
antikceo committed May 6, 2012
1 parent 3c741e2 commit 4937d4a
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
Binary file added SHANNONTEST/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion SHANNONTEST/Course.java
Expand Up @@ -46,7 +46,7 @@ public int numSections()

public String toString()
{
String cString = name + "has sections: ";
String cString = "\n" + name + "has sections: ";
for (Datetime dt1: sections)
cString += dt1.toString() + ", ";

Expand Down
2 changes: 2 additions & 0 deletions SHANNONTEST/Courselist.java
@@ -1,3 +1,5 @@
package chronos.nodes;

import java.util.ArrayList;
public class Courselist implements Comparable<Courselist>{
String name;
Expand Down
Binary file added SHANNONTEST/Scheduler.class
Binary file not shown.
98 changes: 98 additions & 0 deletions SHANNONTEST/Scheduler.java
@@ -0,0 +1,98 @@
import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Scheduler{
int sectionChecker = 0;
String input = null;
int objTracker = 0;
double Credits = 0.0;
//char[] tempChar = null;
String className;
ArrayList<Datetime> date = new ArrayList<Datetime>();
//ArrayList<Datetime> date;
Dayblock dayb;
Timeblock timeb;
Courselist courselist;
Course course = new Course(className, Credits, date) ;

public Scheduler(String input){
this.input = input;
courselist = new Courselist(this.input);
generateCourses(input);
}

public void generateCourses(String input){

try{
String strLine;
int counter = 0;

// open input.txt
FileInputStream fstream = new FileInputStream(input);

// get object of the stream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

//Read File Line By Line
while ((strLine = br.readLine()) != null) {
if(Pattern.matches("\\d+", strLine)){
Double temp = new Double(strLine);
Credits = temp;
course = new Course(className, Credits, date);
courselist.add(course);

System.out.println(course.toString());
objTracker++;
counter = 0;
}
else if(strLine.isEmpty()){
//do nothing

}
else if(counter == 0 ){
className = strLine;
counter = 1;
date = new ArrayList<Datetime>();

}//end of if counter == 0
else{
StringTokenizer st = new StringTokenizer(strLine);
int count = 0;
while (st.hasMoreTokens()) {
if(count == 0){
String temp = new String(st.nextToken());
char[] dayArray = temp.toCharArray();
dayb = new Dayblock(dayArray);
count++;
}
else if(count == 1){
//handle time
String[] times;
//delimiter for split
String delimiter = "-";
String temp = new String(st.nextToken());
times = temp.split(delimiter);
Time timeStart = new Time(times[0]);
Time timeEnd = new Time(times[1]);
timeb = new Timeblock(timeStart,timeEnd);
date.add(new Datetime(dayb, timeb));
}

}//end of while
counter++;
}
}//end of try

in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}

}//generate courses method

public static void main(String args[]) {
Scheduler sched = new Scheduler("input.txt");
}
}
36 changes: 36 additions & 0 deletions SHANNONTEST/input.txt
@@ -0,0 +1,36 @@
Math
W 16:10-17:25
MW 13:10-14:25
3

Stat
TR 13:10-14:25
3

PE
MTR 14:10-15:25
TR 12:00-12:50
1

Chinese
WR 16:10-17:25
MTWR 9:10-10:25
5

ArtHum
W 16:10-17:25
3

PLT
MTR 14:10-15:25
TR 12:00-12:50
1

German
F 16:10-18:25
5

Artificial Intelligence
W 18:10-19:25
MW 16:10-17:25
3
Binary file modified src/main/chronos/.DS_Store
Binary file not shown.
Binary file modified src/main/chronos/nodes/.DS_Store
Binary file not shown.
100 changes: 100 additions & 0 deletions src/main/chronos/nodes/Scheduler.java
@@ -0,0 +1,100 @@
package chronos.nodes;

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Scheduler{
int sectionChecker = 0;
String input = null;
int objTracker = 0;
double Credits = 0.0;
//char[] tempChar = null;
String className;
ArrayList<Datetime> date = new ArrayList<Datetime>();
//ArrayList<Datetime> date;
Dayblock dayb;
Timeblock timeb;
Courselist courselist;
Course course = new Course(className, Credits, date) ;

public Scheduler(String input){
this.input = input;
courselist = new Courselist(this.input);
generateCourses(input);
}

public void generateCourses(String input){

try{
String strLine;
int counter = 0;

// open input.txt
FileInputStream fstream = new FileInputStream(input);

// get object of the stream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

//Read File Line By Line
while ((strLine = br.readLine()) != null) {
if(Pattern.matches("\\d+", strLine)){
Double temp = new Double(strLine);
Credits = temp;
course = new Course(className, Credits, date);
courselist.add(course);

System.out.println(course.toString());
objTracker++;
counter = 0;
}
else if(strLine.isEmpty()){
//do nothing

}
else if(counter == 0 ){
className = strLine;
counter = 1;
date = new ArrayList<Datetime>();

}//end of if counter == 0
else{
StringTokenizer st = new StringTokenizer(strLine);
int count = 0;
while (st.hasMoreTokens()) {
if(count == 0){
String temp = new String(st.nextToken());
char[] dayArray = temp.toCharArray();
dayb = new Dayblock(dayArray);
count++;
}
else if(count == 1){
//handle time
String[] times;
//delimiter for split
String delimiter = "-";
String temp = new String(st.nextToken());
times = temp.split(delimiter);
Time timeStart = new Time(times[0]);
Time timeEnd = new Time(times[1]);
timeb = new Timeblock(timeStart,timeEnd);
date.add(new Datetime(dayb, timeb));
}

}//end of while
counter++;
}
}//end of try

in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}

}//generate courses method

public static void main(String args[]) {
Scheduler sched = new Scheduler("input.txt");
}
}

0 comments on commit 4937d4a

Please sign in to comment.