home / study / engineering / computer science / questions and answers / in a cou
ID: 3694721 • Letter: H
Question
home / study / engineering / computer science / questions and answers / in a course, a teacher gives the following tests ...
Question
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: This method should accept GradeActivity object as its argument. This object should already hold the student's score for the lab activity. Element 0 of the grades field should reference this object.
setPassFailExam: This method should accept PassFailExam object as its argument. This object should already hold the students score for the pass/fail exam. Element 1 of the grades field should reference this object.
setEssay: This method should accept GradedActivity object as its argument. THis object should already hold the student's score for the essay. Element 2 of the grades field should reference this object.
setFinalExam: This method should accept 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.
toString: This methos should return a string that contains the numeric scores and grades for each element in the grades array.
import java.util.Scanner;
public class CourseGradesDemo
{
public static void main(String [] args)
{
//fields for essay imputs
int grammar;
int spelling;
int correctLength;
int content;
//fields for the lab input
int labScore;
//fields for the final exam
int exCorrectQ;
//fields for the pass fail exam
int questions = 10;
int missed = 0;
double minPassing =70;
//New keyboard imput object
Scanner keyboard = new Scanner(System.in);
//Create new Graded Activity object
GradedActivity grade = new GradedActivity();
//Create new PassFail Exam
PassFailExam exam = new PassFailExam(questions, missed, minPassing);
//Create new essay
Essay essay = new Essay();
//Create new course grades
CourseGrades courseGrades = new CourseGrades();
//Welcome message
System.out.println("Welcome to the grade calculator!");
//Get lab activity score
System.out.println("Please enter the score the student recieved on the lab activity: ");
labScore = keyboard.nextInt();
//Get the passfailexam info
System.out.println("Please input the number of questions the student missed: ");
missed = keyboard.nextInt();
//Get the final exam information
System.out.println ("Please input the number of questionst the student got right on the Final Exam");
exCorrectQ = keyboard.nextInt();
//Get information regarding the essay
System.out.println("Last, please input the following information about the students Essay grade");
System.out.println("Please input their Grammar score out of 30 possible points: ");
grammar = keyboard.nextInt();
System.out.println("Please input their Spelling score out of 20 possible points: ");
spelling = keyboard.nextInt();
System.out.println("Please input their Correct Length score out of 20 possible points: ");
correctLength = keyboard.nextInt();
System.out.println("Please input their Content socure out of 30 possible points: ");
content = keyboard.nextInt();
System.out.println(courseGrades.toString());
}
}
public class Essay extends GradedActivity
{
private double grammar;
private double spelling;
private double correctLength;
private double content;
public void setScore(double gr, double sp, double len, double cnt)
{
setGrammar(gr);
setSpelling(sp);
setCorrectLength(len);
setContent(cnt);
super.setScore(grammar + spelling + correctLength + content);
}
private void setGrammar(double g)
{
if (g <= 30.0)
grammar = g;
else
grammar = 0.0;
}
private void setSpelling(double s)
{
if (s <= 20.0)
spelling = s;
else
spelling = 0.0;
}
private void setCorrectLength(double c)
{
if (c <= 20.0)
correctLength = c;
else
correctLength = 0.0;
}
private void setContent(double c)
{
if (c <= 30)
content = c;
else
content = 0.0;
}
public double getGrammar()
{
return grammar;
}
public double getSpelling()
{
return spelling;
}
public double getCorrectLength()
{
return correctLength;
}
public double getContent()
{
return content;
}
public double getScore()
{
return grammar + spelling + correctLength + content;
}
}
public class FinalExam extends GradedActivity
{
private int numQuestions;
private double pointsEach;
private int numMissed;
public FinalExam(int questions, int missed)
{
double numericScore;
numQuestions = questions;
numMissed = missed;
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
setScore(numericScore);
}
public double getPointsEach()
{
return pointsEach;
}
public int getNumMissed()
{
return numMissed;
}
}
public class PassFailActivity extends GradedActivity
{
private double minPassingScore;
public PassFailActivity(double mps)
{
minPassingScore = mps;
}
public char getGrade()
{
char letterGrade;
if (super.getScore() >= minPassingScore)
letterGrade = 'P';
else
letterGrade = 'F';
return letterGrade;
}
}
public class PassFailExam extends PassFailActivity
{
private int numQuestions; // Number of questions
private double pointsEach; // Points for each question
private int numMissed; // Number of questions missed
/**
* The constructor accepts as arguments the number
* of questions on the exam, the number of
* the student missed, and the minimum
* passing score.
*/
public PassFailExam(int questions, int missed,
double minPassing)
{
// Call the superclass constructor.
super(minPassing);
// Declare a local variable for the numeric score.
double numericScore;
// Set the numQuestions and numMissed fields.
numQuestions = questions;
numMissed = missed;
// Calculate the points for each question and
// the numeric score for this exam.
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
// Call the superclass's setScore method to
// set the numeric score.
setScore(numericScore);
}
/**
* The getPointsEach method returns the pointsEach
* field.
*/
public double getPointsEach()
{
return pointsEach;
}
/**
* The getNumMissed method returns the numMissed
* field.
*/
public int getNumMissed()
{
return numMissed;
}
}
public class CourseGrades
{
private GradedActivity grades[];
private final int NUM_GRADES = 4;
/**
* Constructor for objects of class CourseGrades
*/
public CourseGrades()
{
CourseGradesDemo grades = new CourseGradesDemo();
}
public void setLab(PassFailActivity aLab)
{
grades[0] = aLab;
}
public void setPassFailExam(PassFailExam aPassFailExam)
{
grades[1] = aPassFailExam;
}
public void setEssay(Essay anEssay)
{
grades[2] = anEssay;
}
/
public void setFinalExam(FinalExam aFinalExam)
{
grades[3] = aFinalExam;
}
public String toString()
{
String result = "";
result = "Lab Score: " + grades[0] + "Pass/Fail Exam Score: "
+ grades[1].getScore() + " Grade: " + grades[1].getGrade()
+ " Essay Score: " + grades[2].getScore() + " Grade: " + grades[2].getGrade()
+ " Final Exam Score: " + grades[3].getScore() + " Grade: " + grades[3].getGrade();
return result;
}
}
Pelase help me to get it working Im just having a hard time and not much time left.
Explanation / Answer
/**
* The java program CourseGradesDemo that modified
* to execute the classes GradedActivity,PassFailExam
* FinalExam , PassFailActivity and Eassy classes.
*
* */
//CourseGradesDemo.java
import java.util.Scanner;
public class CourseGradesDemo
{
public static void main(String [] args)
{
//fields for essay imputs
int grammar;
int spelling;
int correctLength;
int content;
//fields for the lab input
int labScore;
//fields for the final exam
int exCorrectQ;
//fields for the pass fail exam
int questions = 10;
int missed = 0;
double minPassing =70;
//New keyboard imput object
Scanner keyboard = new Scanner(System.in);
//Welcome message
System.out.println("Welcome to the grade calculator!");
//Get lab activity score
System.out.println("Please enter the score the student recieved on the lab activity: ");
labScore = keyboard.nextInt();
//Create an instance of GradedActivity
GradedActivity lab=new GradedActivity();
//call setScore and set labScore
lab.setScore(labScore);
System.out.println("Please input the number of questions the student missed: ");
missed = keyboard.nextInt();
//Create new PassFail Exam
PassFailExam exam = new PassFailExam(questions, missed, minPassing);
//Get the final exam information
System.out.println ("Please input the number of questionst the student got right on the Final Exam");
exCorrectQ = keyboard.nextInt();
//Create an instance of FinalExam constructor that takes questions and exCorrectQ
FinalExam finalExam=new FinalExam(questions, exCorrectQ);
//Get information regarding the essay
System.out.println("Last, please input the following information about the students Essay grade");
System.out.println("Please input their Grammar score out of 30 possible points: ");
grammar = keyboard.nextInt();
System.out.println("Please input their Spelling score out of 20 possible points: ");
spelling = keyboard.nextInt();
System.out.println("Please input their Correct Length score out of 20 possible points: ");
correctLength = keyboard.nextInt();
System.out.println("Please input their Content socure out of 30 possible points: ");
content = keyboard.nextInt();
//Create new essay
Essay essay = new Essay();
essay.setScore(grammar, spelling, correctLength, content);
//Create an instance of CourseGrades
CourseGrades courseGrades = new CourseGrades();
//Call setLab
courseGrades.setLab(lab);
//Call setPassFailExam
courseGrades.setPassFailExam(exam);
//Call setEassy
courseGrades.setEssay(essay);
//Call setFinalExam
courseGrades.setFinalExam(finalExam);
//Call toString
System.out.println(courseGrades.toString());
}
}
------------------------------------------------------------------------------------------------------
//GradedActivity.java
public class GradedActivity
{
private double score;
public void setScore(double s)
{
score = s;
}
public double getScore()
{
return score;
}
//Returns the grade of score
public char getGrade()
{
char letterGrade;
if (score >= 90)
letterGrade = 'A';
else if (score >= 80)
letterGrade = 'B';
else if (score >= 70)
letterGrade = 'C';
else if (score >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
return letterGrade;
}
}
------------------------------------------------------------------------------------------------------
//PassFailActivity.java
public class PassFailActivity extends GradedActivity
{
private double minPassingScore;
public PassFailActivity(double mps)
{
minPassingScore = mps;
}
public char getGrade()
{
char letterGrade;
if (super.getScore() >= minPassingScore)
letterGrade = 'P';
else
letterGrade = 'F';
return letterGrade;
}
}
------------------------------------------------------------------------------------------------------
//PassFailExam.java
public class PassFailExam extends PassFailActivity
{
private double pointsEach; // Points for each question
private int numMissed; // Number of questions missed
/**
* The constructor accepts as arguments the number
* of questions on the exam, the number of
* the student missed, and the minimum
* passing score.
*/
public PassFailExam(int questions, int missed,
double minPassing)
{
// Call the superclass constructor.
super(minPassing);
// Declare a local variable for the numeric score.
double numericScore;
numMissed = missed;
// Calculate the points for each question and
// the numeric score for this exam.
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
// Call the superclass's setScore method to
// set the numeric score.
setScore(numericScore);
}
/**
* The getPointsEach method returns the pointsEach
* field.
*/
public double getPointsEach()
{
return pointsEach;
}
/**
* The getNumMissed method returns the numMissed
* field.
*/
public int getNumMissed()
{
return numMissed;
}
}
------------------------------------------------------------------------------------------------------
//FinalExam.java
public class FinalExam extends GradedActivity
{
private double pointsEach;
private int numMissed;
public FinalExam(int questions, int missed)
{
double numericScore;
numMissed = missed;
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
setScore(numericScore);
}
public double getPointsEach()
{
return pointsEach;
}
public int getNumMissed()
{
return numMissed;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Essay.java
public class Essay extends GradedActivity
{
private double grammar;
private double spelling;
private double correctLength;
private double content;
public void setScore(double gr, double sp, double len, double cnt)
{
setGrammar(gr);
setSpelling(sp);
setCorrectLength(len);
setContent(cnt);
super.setScore(grammar + spelling + correctLength + content);
}
private void setGrammar(double g)
{
if (g <= 30.0)
grammar = g;
else
grammar = 0.0;
}
private void setSpelling(double s)
{
if (s <= 20.0)
spelling = s;
else
spelling = 0.0;
}
private void setCorrectLength(double c)
{
if (c <= 20.0)
correctLength = c;
else
correctLength = 0.0;
}
private void setContent(double c)
{
if (c <= 30)
content = c;
else
content = 0.0;
}
public double getGrammar()
{
return grammar;
}
public double getSpelling()
{
return spelling;
}
public double getCorrectLength()
{
return correctLength;
}
public double getContent()
{
return content;
}
public double getScore()
{
return grammar + spelling + correctLength + content;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sample output:
Welcome to the grade calculator!
Please enter the score the student recieved on the lab activity:
90
Please input the number of questions the student missed:
2
Please input the number of questionst the student got right on the Final Exam
7
Last, please input the following information about the students Essay grade
Please input their Grammar score out of 30 possible points:
30
Please input their Spelling score out of 20 possible points:
20
Please input their Correct Length score out of 20 possible points:
20
Please input their Content socure out of 30 possible points:
30
Lab Score: 90.0 Grade: A
Pass/Fail Exam Score: 80.0 Grade: P
Essay Score: 100.0 Grade: A
Final Exam Score: 30.0 Grade: F
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.