/* Tuesday pm lecture - Part 1: Methods for Simple Classes +--------------+ | GradeRecord | +--------------+ | int number | | String title | | int credits | | double grade | +--------------+ */ // to represent a grade record on a transcript class GradeRecord { int number; String title; int credits; double grade; GradeRecord(int number, String title, int credits, double grade) { this.number = number; this.title = title; this.credits = credits; this.grade = grade; } /* TEMPLATE: ... this.number ... -- int ... this.title ... -- String ... this.credits ... -- int ... this.grade ... -- double ... this.qPoints() ... -- double ... this.okCourse(double level) ... -- boolean ... this.higherGrade(GradeRecord that) ... -- boolean */ // compute the quality points earned in this course double qPoints(){ return this.grade * this.credits; } // does this grade record earn quality points above the given level? boolean okCourse(double level) { return this.qPoints() >= level; } // is the grade in this grade record higher that in the given record boolean higherGrade(GradeRecord that) { return this.grade > that.grade; } } // client class for the GradeRecord class class ExamplesGradeRecord{ ExamplesGradeRecord() {} // sample grade records GradeRecord fund = new GradeRecord(211, "Fundamentals", 4, 3.66); GradeRecord ovw = new GradeRecord(220, "Overview", 1, 4.0); GradeRecord algo = new GradeRecord(690, "Algorithms", 4, 3.0); // test the method qPoints: boolean test1 = check this.fund.qPoints() expect 14.64 within 0.01; boolean test2 = check this.ovw.qPoints() expect 4.0 within 0.01; boolean test3 = check this.algo.qPoints() expect 12.0 within 0.01; // test the method okCourse: boolean test4 = check this.fund.okCourse(14.0) expect true; boolean test5 = check this.algo.okCourse(14.0) expect false; // test the method higherThan: boolean test6 = check this.fund.higherGrade(this.ovw) expect false; boolean test7 = check this.fund.higherGrade(this.algo) expect true; }