"Cannot find symbol" compilation error
Hi! I have two errors in my code when I try to compile, in the lines " Course newCourse = new Course(cName, cStart, cEnd);" and "lastEnd = course.getETime;" and I'm not sure why the code is having trouble accessing the course class. Any help would be appreciated.
Code :
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! The Course class can be posted if necessary
Re: "Cannot find symbol" compilation error
Please post the full text of the error messages. Your edited version leaves off important information.
Re: "Cannot find symbol" compilation error
Quote:
Originally Posted by
Norm
Please post the full text of the error messages. Your edited version leaves off important information.
./Fitter.java:56: cannot find symbol
symbol: constructor Course(java.lang.String,java.lang.String,java.lang .String)
location: class Course
Course newCourse = new Course(cName, cStart, cEnd);
./Fitter.java:71: cannot find symbol
symbol: variable getETime
location: class Course
lastEnd = course.getETime;
Re: "Cannot find symbol" compilation error
Quote:
Course(java.lang.String,java.lang.String,java.lang .String)
Does the Course class have a constructor that takes 3 Strings?
Quote:
cannot find symbol
symbol: variable getETime
The compiler can not find that variable in the Course class.
Re: "Cannot find symbol" compilation error
Quote:
Originally Posted by
Norm
Does the Course class have a constructor that takes 3 Strings?
Yes - it's written as
Code :
public Course(String cName, double cStart, double cEnd){
...
}
The compiler can not find that variable in the Course class.[/QUOTE]
Just realized, I forgot the parentheses. Sorry about that; that was a silly mistake...
Re: "Cannot find symbol" compilation error
You must count differently than I do. I see one String followed by two doubles in the constructor code that you just posted in #5.
Re: "Cannot find symbol" compilation error
Quote:
Originally Posted by
collegejavastudent
Yes - it's written as
Code :
public Course(String cName, double cStart, double cEnd){
...
}
How are you sure this is 3 Strings?
Re: "Cannot find symbol" compilation error
Aaah, just realized that I left out the code in which I was going to make that a double...
Thanks! Don't I feel silly...