5. Course Grades In a course, a teacher gives the following tests and assignment
ID: 3720439 • Letter: 5
Question
5. Course Grades In a course, a teacher gives the following tests and assignments: • A lab activity that is observed by the teacher and assigned a numeric score. • A pass/fail exam that has 10 questions. The minimum passing score is 70. • An essay that is assigned a numeric score. • A final exam that has 50 questions. Write a class named CourseGrades. The class should have a GradedActivity array named grades as a field. The array should have four elements, one for each of the assignments previously described. The class should have the following methods: setLab: setPassFailExam: setEssay: setFinalExam: toString: This method should accept a GradedActivity object as its argu- ment. This object should already hold the student’s score for the lab activity. Element 0 of the grades field should reference this object. This method should accept a PassFailExam object as its argument. This object should already hold the student’s score for the pass/fail exam. Element 1 of the grades field should reference this object. This method should accept an Essay object as its argument. (See Programming Challenge 4 for the Essay class. If you have not completed Programming Challenge 4, use a GradedActivity object instead.) This object should already hold the student’s score for the essay. Element 2 of the grades field should reference this object. This method should accept a FinalExam object as its argument. This object should already hold the student’s score for the final exam. Element 3 of the grades field should reference this object. This method should return a string that contains the numeric scores and grades for each element in the grades array. Demonstrate the class in a program. 5. Course Grades In a course, a teacher gives the following tests and assignments: • A lab activity that is observed by the teacher and assigned a numeric score. • A pass/fail exam that has 10 questions. The minimum passing score is 70. • An essay that is assigned a numeric score. • A final exam that has 50 questions. Write a class named CourseGrades. The class should have a GradedActivity array named grades as a field. The array should have four elements, one for each of the assignments previously described. The class should have the following methods: setLab: setPassFailExam: setEssay: setFinalExam: toString: This method should accept a GradedActivity object as its argu- ment. This object should already hold the student’s score for the lab activity. Element 0 of the grades field should reference this object. This method should accept a PassFailExam object as its argument. This object should already hold the student’s score for the pass/fail exam. Element 1 of the grades field should reference this object. This method should accept an Essay object as its argument. (See Programming Challenge 4 for the Essay class. If you have not completed Programming Challenge 4, use a GradedActivity object instead.) This object should already hold the student’s score for the essay. Element 2 of the grades field should reference this object. This method should accept a FinalExam object as its argument. This object should already hold the student’s score for the final exam. Element 3 of the grades field should reference this object. This method should return a string that contains the numeric scores and grades for each element in the grades array. Demonstrate the class in a program. 5. Course Grades In a course, a teacher gives the following tests and assignments: • A lab activity that is observed by the teacher and assigned a numeric score. • A pass/fail exam that has 10 questions. The minimum passing score is 70. • An essay that is assigned a numeric score. • A final exam that has 50 questions. Write a class named CourseGrades. The class should have a GradedActivity array named grades as a field. The array should have four elements, one for each of the assignments previously described. The class should have the following methods: setLab: setPassFailExam: setEssay: setFinalExam: toString: This method should accept a GradedActivity object as its argu- ment. This object should already hold the student’s score for the lab activity. Element 0 of the grades field should reference this object. This method should accept a PassFailExam object as its argument. This object should already hold the student’s score for the pass/fail exam. Element 1 of the grades field should reference this object. This method should accept an Essay object as its argument. (See Programming Challenge 4 for the Essay class. If you have not completed Programming Challenge 4, use a GradedActivity object instead.) This object should already hold the student’s score for the essay. Element 2 of the grades field should reference this object. This method should accept a FinalExam object as its argument. This object should already hold the student’s score for the final exam. Element 3 of the grades field should reference this object. This method should return a string that contains the numeric scores and grades for each element in the grades array. Demonstrate the class in a program.Explanation / Answer
//question was little ambigous. so i inferred the finalexam, passfailexam, essay are child objects of GradedActivity //class
//parent class stroing score. it can store objects of child also
//that is why GradedActivity array can store other child objects of this class
class GradedActivity{
double score;
public GradedActivity(double score) {
this.score=score;
}
}
//this is child class of GradedActivity class it stores finalexam score
class FinalExam extends GradedActivity{
//this stores score of particular exam i.e final exam score
double score;
//this is a default constructor which calls parent class GradedActivity constructor
public FinalExam(double score) {
super(score);
this.score=score;
}
}
//this is child class of PassFailExam class it stores PassFailExam score
class PassFailExam extends GradedActivity{
//this stores score of particular exam i.e PassFailExam score
double score;
//this is a default constructor which calls parent class GradedActivity constructor
public PassFailExam(double score) {
super(score);
this.score=score;
}
}
//this is child class of Essay class it stores Essay score
class Essay extends GradedActivity{
//this stores score of particular exam i.e Essay score
double score;
//this is a default constructor which calls parent class GradedActivity constructor
public Essay(double score) {
super(score);
this.score=score;
}
}
public class CourseGrades {
GradedActivity[] grades=new GradedActivity[4];
double labScore;
double passFailScore;
double essayScore;
double finalExamScore;
public void setLab(GradedActivity activity) {
this.labScore=activity.score;
}
public void setPassFailExam(PassFailExam activity) {
this.passFailScore=activity.score;
}
public void setEssay(Essay activity) {
this.essayScore=activity.score;
}
public void setFinalExam(FinalExam activity) {
this.finalExamScore=activity.score;
}
@Override
public String toString() {
return "Lab exam score "+this.grades[0].score+
" PassFail exam score "+this.grades[1].score+
" Essay score "+this.grades[2].score+
" Final exam score "+this.grades[3].score;
}
public static void main(String[] args) {
CourseGrades courseGrades=new CourseGrades();
//these stores the grades array which contains four elements to store the score of above exams
courseGrades.grades[0]=new GradedActivity(80);
courseGrades.grades[1]=new PassFailExam(90);
courseGrades.grades[2]=new Essay(80);
courseGrades.grades[3]=new FinalExam(70);
//these set the exam score of particular exam
courseGrades.setLab(courseGrades.grades[0]);
courseGrades.setPassFailExam((PassFailExam) courseGrades.grades[1]);
courseGrades.setEssay((Essay) courseGrades.grades[2]);
courseGrades.setFinalExam((FinalExam) courseGrades.grades[3]);
//this prints the string representation of scores and grades
System.out.println(courseGrades);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.