java - Why can't a course[] object follow a pointer to a double? -
for java programming class, trying write program tell if classes conflict. far, have object called course. public void init initialize courses members noted above, public boolean conflict(scanner scan) find our conflicts schedules. , public string tostring returns name , time of course. question is, due compiling error have noted on attached photo, how set othercourse compare times , end time considering othercourse course[] (course array) pointer?
so far, have tried othercourse[i].end_time = time + length / class_period * per + length % class_period; , sends symbol cannot found compiling error.
the same goes if statement, if (othercourse[i].length course.time && course.time < othercourse[i].length)
i wondering how set othercourse.time , othercourse.length appropriately follow pointers. thank in advance.
import java.util.*; public class course { public static final int class_period = 60; public static final double per = 100; public string name; // ie: cs142, cs141, eng 101 public string instructor; // ie: john mill, bob fish public string room; // ie: 127a, 18-218, bathroom public int time; // in military notation. ie: 1030, 1600 etc public int length; // length in minutes. 50 means course // lasts 50 minutes. public double end_time; // name: init // desc: reads in entries members user // params: scanner scan // return: void // 1) each member steps 2-3. // 2) prompt user enter value // 3) read in value , store in member public void init(scanner scan) { //steps 1-3 system.out.print("please enter in course name: "); name = scan.next(); system.out.print("please enter in name of instructor: "); instructor = scan.next(); system.out.print("please enter in room number: "); room = scan.next(); system.out.print("please enter in start time: "); time = scan.nextint(); system.out.print("please enter in length of course: "); length = scan.nextint(); } // name: conflict // desc: returns true if course conflicts parameter // params: course othercourse // return: boolean - true if courses conflict // 1) if course , othercourse start @ same time, return true // 2) calculate end time of course ( start time + length/60*100 + // length % 60 ) // 3) calculate end of othercourse // 4) if course starts after other course, , starts before // other course ends, return true // 5) if other course starts after course, , starts before // course ends, return true // 6) return false public boolean conflict(course[] othercourse, course course) { //step 1 if (this.time == othercourse.time) return true; //step 2 course.end_time = time + length / class_period * per + length % class_period; //step 3 othercourse.end_time = time + length / class_period * per + length % class_period; //step 4 if (this.time > othercourse.length && course.length < othercourse.time) return true; //step 5 if (othercourse.length course.time && course.time < othercourse.length) return true; //step 6 return false; } // name: print // desc: returns string represents basic info course // params: none // return: string // 1) return string of format "course " + name + " start time " + // time public string tostring() { return name + time; } }
so first thing's first. method (as per comments even) should take 1 parameter, course being compared to. have current courses information in global scope. method signature follows:
public boolean conflict(course othercourse) { for step 3, need using othercourse's information.
//step 3 othercourse.end_time = othercourse.time + othercourse.length / othercourse.class_period * othercourse.per + othercourse.length % othercourse.class_period; and now, when call method, it's
othercourse[i].conflict(course); in addition, anywhere reference course replace this or remove (i.e. course.time becomes this.time or time).
Comments
Post a Comment