I have an assignment to gather information on students and their grades and then display the information using a for loop. I have the following code but it is not displaying the information correctly. Any help would be great.
public class Grader
{
String last;
String assign;
int score;
String letterGrade;
public Grader(String lastName, String assignment, int grade, String letterGrade)
{
last = lastName;
assign = assignment;
score = grade;
}
public String getStudent()
{
return last;
}
public String getAssignment()
{
return assign;
}
public int getScore()
{
return score;
}
public String getGrade()
{
if (score <= 59)
letterGrade = "F";
else if (score >= 60 && score <= 69)
letterGrade = "D";
else if (score >= 70 && score <= 72)
letterGrade = "C-";
else if (score >= 73 && score <= 76)
letterGrade = "C";
else if (score >= 77 && score <= 79)
letterGrade = "C+";
else if (score >= 80 && score <= 82)
letterGrade = "B-";
else if (score >= 83 && score <= 86)
letterGrade = "B";
else if (score >= 87 && score <= 89)
letterGrade = "B+";
else if (score >= 90 && score <= 92)
letterGrade = "A-";
else if (score >= 93 && score <= 96)
letterGrade = "A";
else if (score >= 97 && score <= 100)
letterGrade = "A+";
return letterGrade;
}
}
import java.util.Scanner;
public class GradeTester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int x = 0;
System.out.print("Enter number of students: ");
x = in.nextInt();
for (int i = 0; i < x; i++)
{
String letterGrade = "";
System.out.print("Enter the students last name: ");
String lastName = in.next();
System.out.print("Enter the assignment: ");
String assignment = in.next();
System.out.print("Enter the grade: ");
int grade = in.nextInt();
for (int j = 0; j < x; j++)
{
Grader grade1 = new Grader(lastName, assignment, grade, letterGrade);
System.out.print(grade1.getStudent() + grade1.getAssignment() + grade1.getScore() + grade1.getGrade());
}
}
}
}