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

//java Public class grade { private char letterGrade; public Grade ( char letter

ID: 3772018 • Letter: #

Question

//java

Public class grade

{

       private char letterGrade;

       public Grade ( char letterGrade )

         {

           letterGrade = LetterGrade;

           }

          public char getLetterGrade()

          {

          return letterGrade;

          }

}

In the main method of the class GradeClient you have:

Grade g1 = new Grade( 'A');

System.out.println(g1.getLetterGrade());

The code compiles and runs, but the output is just a space, not the desired ouput of A

What is the problem and how do I fix it?

Explanation / Answer

Program:

//file: Grade.java
import java.util.*;
import java.lang.*;
import java.io.*;

public class Grade
{
private char letterGrade;          
public Grade ( char letterGrade )          
{
this.letterGrade = letterGrade;    // setting the letterGrade value
}
public char getLetterGrade()
{
return letterGrade;           // returning letterGrade value
}
public static void main (String[] args) throws java.lang.Exception
{
Grade g1 = new Grade('A');       // Initializing object g1
System.out.println(g1.getLetterGrade()); // printing the output
  
}
}

Output:

A