Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, this is a java programming assignment. Please provide a full code for thi

ID: 3866051 • Letter: H

Question

Hello, this is a java programming assignment. Please provide a full code for this program. Thank you.

Programming Project: 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 e xam that has 10 questions. The minimum passing score is 70.

An essay that is assigned a numeric score.

A final e xam that has 50 questions.

Write a class named CourseGrades that implements the following interface:

public interface Analyzable

{

      double getAverage();

      GradedActivity getHighest();

      GradedActivity getLowest();

}

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 a GradedActivity 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.

setPassFailE xam: 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.

setEssay: This method should accept an Essay object as its argument. The Essay class extends the GradedActivity class presented in this chapter. The Essay class should determine the grade a student receives for an essay. The student's essay score can be up to 100 and is determined in the following manner: 1) Grammar: 30 points, 2) Spelling: 20 points, 3) Correct length: 20 points, and Content: 30 points. Element 2 of the grades field should reference this object.

setFanalE xam: This method should accept a FinalExam object as tis 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 method should return a string that contains the numeric scores and grades for each element in the grades array.

Demonstrate the class with a driver program.

Sample Output:

Lab Score: 85.0 Grade: B
Pass/Fail E xam Score: 85.0      Grade: P
Essay Score: 80.0       Grade: B
Final E xam Score: 80.0 Grade: B
Average score: 82.5
Highest score: 85.0
Lowest score: 80.0
Press any key to continue . . .

Explanation / Answer

Here is the code segment as per given question:-

//-------------------------------------------------------------

public class Course_Grades_Sample
{
public static void main(String[] args)
{
// Create an object for the lab grade.
GradedActivity lab = new GradedActivity();
  
// Set the lab highest socre at 85.
lab.setScore(85);
  
  
// Create an object for the pass/fail e_xam.
// 20 total questions, 3 questions missed, minimum
// passing score is 70.

PassFail_e_xam pf_e_xam = new PassFail_e_xam(20, 3, 70);

   // Create an object for the essay grade.
Essay essay = new Essay();
  
// Set the essay scores. Grammer = 25, spelling = 18
// length = 17, content = 20.
essay.setScore(25, 18, 17, 20);
  

// Create an object for the final e_xam.
// 50 questions, 10 missed.

Final_e_xam Final_e_xam = new Final_e_xam(50, 10);
  

// Create a CourseGrades object.
CourseGrades course = new CourseGrades();
course.setLab(lab);
course.setPassFail_e_xam(pfe_xam);
course.setEssay(essay);
course.setFinal_e_xam(Final_e_xam);
  

// Display the scores and grades.
System.out.println(course);
}
}

GradedActivity.java

/**
The GradedActivity class stores data about a graded  activity for the Analyzable Interface programming
challenge.
*/

public class GradedActivity
{
private double score; // Numeric score

   /**
The setScore method sets the score field.
@param s The value to store in score.
*/

public void setScore(double s)
{
score = s;
}

/**
The getScore method returns the score.
@return The value stored in the score field.
*/

public double getScore()
{
return score;
}

   /**
The getGrade method returns a letter grade determined from the score field.
@return The letter grade.
*/

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;
}
}

PassFail_e_xam.java

/**
The PassFail_e_xam class stores data about a graded activity that is an e_xam and has a passing or failing
grade for the Course Grades programming challenge.
*/

public class PassFail_e_xam extends PassFailActivity
{
private int numQuestions; // Number of questions
private double pointsEach; // Points for each question
private int numMissed; // Number of questions missed

/**
The constructor sets the number of questions, the number of questions missed, and the minimum passing score.
@param questions The number of questions.
@param missed The number of questions missed.
@param minPassing The minimum passing score.
*/

public PassFail_e_xam(int questions, int missed,
double minPassing)
{
  
// Call the superclass constructor.
super(minPassing);

  // Declare a local variable for the 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 e_xam.
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 number of points each question is worth.
@return The value in the pointsEach field.
*/

public double getPointsEach()
{
return pointsEach;
}

   /**
The getNumMissed method returns the number of questions missed.
@return The value in the numMissed field.
*/

public int getNumMissed()
{
return numMissed;
}
}

PassFailActivity.java

/**
The PassFailActivity class stores data about a graded activity that has a passing or failing grade for the Analyzable Interface programming challenge.
*/

public class PassFailActivity extends GradedActivity
{
private double minPassingScore; // Minimum passing score

/**
The constructor sets the minimum passing score.
@param mps The minimum passing score.
*/

public PassFailActivity(double mps)
{
minPassingScore = mps;
}

   /**
The getGrade method returns a letter grade determined from the score field. This
method overrides the superclass method.
@return The letter grade.
*/

@Override
public char getGrade()
{
char letterGrade;

if (super.getScore() >= minPassingScore)
letterGrade = 'P';
else
letterGrade = 'F';

return letterGrade;
}
}

CourseGrades.java

/**
The CourseGrades class stores data about a course's graded activities for the Course Grades programming challenge.
*/

public class CourseGrades implements Analyzable
{
// Constant for the number of grades
public final int NUM_GRADES = 4;

   // Variable to reference a GradedActivity
// array
private GradedActivity[] grades;

/**
Constructor
*/

  
public CourseGrades()
{
  
// Create the grades array.
grades = new GradedActivity[NUM_GRADES];
}

   /**
The setLab method stores a GradedActivity object for the lab grade.
@param aLab Represents the lab grade.
*/

public void setLab(GradedActivity aLab)
{
grades[0] = aLab;
}

  /**
The setPassFail_e_xam method stores a PassFail_e_xam object for the pass/fail e_xam grade.
@param aPassFail_e_xam Represents the pass/fail e_xam grade.
*/

public void setPassFail_e_xam(PassFail_e_xam aPassFail_e_xam)
{
grades[1] = aPassFail_e_xam;
}

  /**
The setEssay method stores an Essay object for the essay grade.
@param anEsay Represents the essay grade.
*/

  
public void setEssay(Essay anEssay)
{
grades[2] = anEssay;
}

  /**
The setFinal_e_xam method stores a Final_e_xam object for the final e_xam grade.
@param aFinal_e_xam Represents the final e_xam grade.
*/

public void setFinal_e_xam(Final_e_xam aFinal_e_xam)
{
grades[3] = aFinal_e_xam;
}

  /**
The toString method returns a string representation of the object.
@return A string representation of the object.
*/

public String toString()
{
String str = "Lab Score: " + grades[0].getScore() +
" Grade: " + grades[0].getGrade() +
" Pass/Fail e_xam Score: " + grades[1].getScore() +
" Grade: " + grades[1].getGrade() +
" Essay Score: " + grades[2].getScore() +
" Grade: " + grades[2].getGrade() +
" Final e_xam Score: " + grades[3].getScore() +
" Grade: " + grades[3].getGrade()+
" Average Score: " + String.format("%,.2f%%",getAverage()) +
" Highest Score: " + String.format("%,.2f%%",getHighest().getScore()) +
" Lowest Score: " + String.format("%,.2f%%",getLowest().getScore());
return str;
  
  
}
  
  //method used to calculate the average grade score
@Override
public double getAverage() {
double avg = 0;
for(int i = 0;i < grades.length;i++){
avg += grades[i].getScore();
}
avg = avg / grades.length;
return avg;
}

//method used to find the highest value in the array
@Override
public GradedActivity getHighest() {
double high = grades[0].getScore();
int temp = 0;
for(int i = 0;i < grades.length;i++){
if(grades[i].getScore() > high){
temp = i;
}
  
}
return grades[temp];
}

  //method used to find the lowest value in the array
@Override
public GradedActivity getLowest() {
double low = grades[0].getScore();
int temp = 0;
for(int i = 0;i < grades.length;i++){
if(grades[i].getScore() < low){
temp = i;
}
  
}
return grades[temp];
}
}

Essay.java

/**
The Essay class stores data about a graded activity that is an essay for the Analyzable Interface programming challenge.
*/

public class Essay extends GradedActivity
{
private double grammar;
// Points for grammar
private double spelling;   // Points for spelling
private double correctLength; // Points for length
private double content; // Points for content

  /**
The setScore method sets points for grammar, spelling, length, and content. This method overloads the super class method.
Note that the other "set" methods are private. Those methods are for validating points before they are assigned.
@param gr Grammar points.
@param sp Spelling points.
@param len Length points.
@param cnt Content points.
*/

public void setScore(double gr, double sp, double len, double cnt)
{
   // Set the individual scores.
setGrammar(gr);
setSpelling(sp);
setCorrectLength(len);
setContent(cnt);
  
  
// Set the total score.
super.setScore(grammar + spelling + correctLength + content);
}

   /**
The setGrammar method sets the grammar points, validating them before they are set.
@param g Grammar points.
*/

private void setGrammar(double g)
{
if (g <= 30.0)
grammar = g;
else
// Invalid points
grammar = 0.0;
}

   /**
The setSpelling method sets the spelling points, validating them before they are set.
@param s Spelling points.
*/

private void setSpelling(double s)
{
if (s <= 20.0)
spelling = s;
else   
// Invalid points
spelling = 0.0;
}

/**
The setCorrectLength method sets the points for correct length, validating them before they are set.
@param c Correct length points.
*/

private void setCorrectLength(double c)
{
if (c <= 20.0)
correctLength = c;
else   
// Invalid points
correctLength = 0.0;
}

  /**
The setContent method sets the points for content, validating them before they are set.
@param c Content points.
*/

private void setContent(double c)
{
if (c <= 30)
content = c;
else
// Invalid points
content = 0.0;
}

   /**
The getGrammar method returns the points awarded for grammar.
@return Gramar points.
*/

public double getGrammar()
{
return grammar;
}

   /**
The getSpelling method returns the points awarded for spelling.
@return Spelling points.
*/

public double getSpelling()
{
return spelling;
}

/**
The getCorrectLength method returns the points awarded for correct length.
@return Correct length points.
*/

public double getCorrectLength()
{
return correctLength;
}

/**
The getContent method returns the points awarded for content.
@return Content points.
*/

public double getContent()
{
return content;
}

   /**
The getScore method returns the overall numeric score. Overrides the base class
method.
@return Overall numeric score.
*/

@Override
public double getScore()
{
return grammar + spelling + correctLength + content;
}
}

Final_e_xam.java

/**
The Essay class stores data about a graded activity that is a final e_xam for the Analyzable Interface programming challenge.
*/

public class Final_e_xam extends GradedActivity
{
private int numQuestions;
// Number of questions
private double pointsEach; // Points for each question
private int numMissed;   // Questions missed

  /**
The constructor sets the number of questions on the e_xam and the number of questions missed.
@param questions The number of questions.
@param missed The number of questions missed.
*/

public Final_e_xam(int questions, int missed)
{
double numericScore;
// To hold a numeric score

// Set the numQuestions and numMissed fields.
numQuestions = questions;
numMissed = missed;

   // Calculate the points for each question and
// the numeric score for this e_xam.
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);

   // Call the inherited setScore method to
// set the numeric score.
setScore(numericScore);
}

  /**
The getPointsEach method returns the number of points each question is worth.
@return The value in the pointsEach field.
*/

public double getPointsEach()
{
return pointsEach;
}

   /**
The getNumMissed method returns the number of questions missed.
@return The value in the numMissed field.
*/

public int getNumMissed()
{
return numMissed;
}
}

Analyzable.java


public interface Analyzable {

double getAverage();
GradedActivity getHighest();
GradedActivity getLowest();
}