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.

Recommended Answers

All 4 Replies

well, considering the first of your messages states he's not finding a certain constructor of the course class you are calling, that would be extremely helpful.
the second line, you should remember you need to end all methods (and method calls) with () (unless off course you need to pass parameters to the method.)

Thanks. I figured out the second line.

Here's the Course class:

public class Course implements Comparable<Course>{
	
	private String name;
	private double cStart;
	private double cEnd;
	
	public Course(String cName, double cStart, double cEnd) {
		this.name = cName;
		this.cStart = cStart;
		this.cEnd = cEnd;
	}
		
	public String getName() {
		return name;
	}
	
	public double getSTime() {
		return cStart;
	}

	public double getETime() {
		return cEnd;
	}

	public int compareTo(Course c) {
		if(cEnd > c.getETime())
			return 1;
		else if(cEnd < c.getETime())
			return -1;
		return 0;
	}

}

Just realized the code I was missing.

Thanks!

Course newCourse = new Course(cName, cStart, cEnd);

you're calling the constructor with the Strings cStart and oEnd, you should use doubles

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.