Create a class named Grade. Include fields for a student ID number, student name
ID: 3634184 • Letter: C
Question
Create a class named Grade. Include fields for a student ID number, student name, numeric test score, possible points, and letter grade. The constructor requires the student ID, name, test score, and should have a fourth parameter that holds "possible test points."If the value for "possible test points"is not passed to the constructor, then the possible points value should default to 100. The constructor calculates the student’s percentage by dividing a score by the possible points , then should assign a letter grade based on: 90% and above =A, 80%=B, 70% = C, and 60% = D.
Explanation / Answer
// Create a class named Grade.
public class Grade
{
// Include fields for a student ID number, student name, numeric test score, possible points, and letter grade.
private int id;
private String name;
private int score;
private int possiblePoints;
private char letterGrade;
// The constructor requires the student ID, name, test score, and should have a fourth parameter that holds "possible test points."
public Grade(int id, String name, int score, int possiblePoints)
{
this.id = id;
this.name = name;
this.score = score;
this.possiblePoints = possiblePoints;
// The constructor calculates the student’s percentage by dividing a score by the possible points , then should assign a letter grade based on: 90% and above =A, 80%=B, 70% = C, and 60% = D.
double percentage = 100.0*score/possiblePoints;
if(percentage >= 90)
letterGrade = 'A';
else if(percentage >= 80)
letterGrade = 'B';
else if(percentage >= 70)
letterGrade = 'C';
else if(percentage >= 60)
letterGrade = 'D';
else
letterGrade = 'F';
}
// If the value for "possible test points"is not passed to the constructor, then the possible points value should default to 100.
public Grade(int id, String name, int score)
{
this(id, name, score, 100);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.