Hi! Two errors pop up when I try to compile this code (to organize classes and fit as many as possible in a schedule), in the lines "Course newCourse = new Course(cName, cStart, cEnd);" and "lastEnd = course.getETime;"
I'm not sure why the code is having trouble accessing the course class. Any help would be appreciated.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Fitter {
private ArrayList<Course> courses;
private ArrayList<Course> fittedCourses;
private double cEndTime;
private double cStartTime;
private double lastEnd = 8;
public Fitter(File courseList) throws FileNotFoundException, NumberFormatException{
//initialize variables
courses = new ArrayList<Course>();
fittedCourses = new ArrayList<Course>();
Scanner courseScanner = new Scanner(courseList);
//scan lines in File
while(courseScanner.hasNextLine()) {
//get name and start/ end times
String cName = courseScanner.nextLine();
String cStart = courseScanner.nextLine();
String cEnd = courseScanner.nextLine();
//convert times into decimals, first checking number formatting
String[] cStartSplit = cStart.split(":");
double cStartH = Double.parseDouble(cStartSplit[0]);
double cStartM = Double.parseDouble(cStartSplit[1]);
if ((cStartH < 8) || (cStartH > 17))
throw new NumberFormatException();
if (cStartM > 60)
throw new NumberFormatException();
String[] cEndSplit = cEnd.split(":");
double cEndH = Double.parseDouble(cEndSplit[0]);
double cEndM = Double.parseDouble(cEndSplit[1]);
if ((cEndH < 8) || (cEndH > 17))
throw new NumberFormatException();
if (cStartM > 60)
throw new NumberFormatException();
Course newCourse = new Course(cName, cStart, cEnd);
courses.add(newCourse);
//skip blank line
if(courseScanner.hasNextLine())
courseScanner.nextLine();
}
}
public void fit() throws NumberFormatException{
//sort by size
Collections.sort(courses);
//for each course (starting with earliest end time) add
//if no conflict exists
for(Course course : courses) {
if(lastEnd < course.getSTime())
lastEnd = course.getETime;
}
}
public String toString() {
String info = "We made the following schedule: \n\n";
for(Course course : fittedCourses) {
info += course.toString() + "\n";
}
return info;
}
}
Thanks! I can post the Course class if it helps.