0

The following method is supposed to compare the start time, the end time, and duration of one course to another course but as I use the parameter instance(Course othercourse), it is giving out a cannot find symbol compiler error in Java and I do not understand why. Course.java follows as below.

    import java.util.*;

    public class Course{
    private String name; // ie: CS142, CS141, ENG 101
    private String instructor; // ie: John Mill, Bob the Fish
    private String room; // ie: 127A, 18-218, the bathroom
    private int time; // in military notation.  ie: 1030, 1600 etc
    private int length; // length in minutes.  50 means the course
                   // lasts 50 minutes. 

 // name: init
// desc: reads in entries for the members from the user
// params: Scanner scan
// return: void  
// 1) for each member do steps 2-3.    
// 2)  prompt the user to enter a value
// 3)  read in that value and store in the member

    public void init(Scanner scan){

    //Step 1-Done

    //Steps 2 and 3
    System.out.print("Please enter in a name: ");
    name = scan.next();

    System.out.print("Please enter in an instructor: ");
    instructor = scan.next();

    System.out.print("Please enter in a room: ");
    room = scan.next();

    System.out.print("Please enter in a time: ");
    time = scan.nextInt();

    System.out.print("Please enter in a length of time: ");
    length = scan.nextInt();
    }

// name: conflict
// desc: returns true if this course conflicts with the parameter
// params: Course othercourse
// return: boolean - true if the courses conflict
// 1) if this course and othercourse start at the same time, return true
// 2) calculate the end time of this course ( start time + length/60*100 + 
//      length % 60 )
// 3) calculate the end of the othercourse
// 4) if this course starts after other course, and starts before 
//  the other course ends, return true
// 5) if the other course starts after this course, and starts before
//  this course ends, return true
// 6) return false

public boolean conflict(Course othercourse){
    double end_time;
    //Step 1
    if(time == othercourse.time)
        return true;
    //Step 2
    end_time = (double) time + length/ 60 * 100 + length % 60;

    //Step 3
    othercourse.end_time = (double) othercourse.time + othercourse.length/ 60 * 100 + othercourse.length % 60;
    //Step 4
    if(time+length > othercourse.time+othercourse.length && time+length < othercourse.end_time)
        return true;

    //Step 5
    if(othercourse.time+length > time+length && othercourse.time+length < end_time)
        return true;

    //Step 6
    return false;

    }

// name: print
// desc: returns a string that represents some basic info about the course 
// params: none
// return: String
// 1) return a string of the format "Course " + name + " with start time " + 
//    time

    public String print(){
    return "Course: "+name+" with start time: "+time;
    }

}//End Class

Basically, this.anything or othercourse.anything is a cannot find symbol error. When I use the parameter's instance, it the compiler isn't liking it. Any help is greatly appreciated. Thanks in advance.

0 Answers0