Skip to content
Browse files

Added Scheduler.java (contains generate courses method)

  • Loading branch information...
1 parent 3c741e2 commit 4937d4a16d9eba46108dd5823ea358ac05403dd3 @antikceo antikceo committed
View
BIN .DS_Store
Binary file not shown.
View
BIN SHANNONTEST/.DS_Store
Binary file not shown.
View
2 SHANNONTEST/Course.java
@@ -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() + ", ";
View
2 SHANNONTEST/Courselist.java
@@ -1,3 +1,5 @@
+package chronos.nodes;
+
import java.util.ArrayList;
public class Courselist implements Comparable<Courselist>{
String name;
View
BIN SHANNONTEST/Scheduler.class
Binary file not shown.
View
98 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");
+ }
+}
View
36 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
View
BIN src/main/chronos/.DS_Store
Binary file not shown.
View
BIN src/main/chronos/nodes/.DS_Store
Binary file not shown.
View
100 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.
Something went wrong with that request. Please try again.