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

What do you mean it's not displaying correctly? I guess your output would look something like studentNameAssignmentNameScoreGrade because that is how you call it from line 34. If you would like to tidy it up do something like

Grader grade1 = new Grader(lastName, assignment, grade, letterGrade);
System.out.println("Student: " + grade1.getStudent());
System.out.println("Assignment: " + grade1.getAssignment());
System.out.println("Score: " + grade1.getScore());
System.out.println("Grade: " + grade1.getGrade());

inside the for-loop. Another (even better) way is to override the toString() method in Grader and just call grade1.toString() for the object to be printed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.