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

This is what I have so far please help Write an application that displays a seri

ID: 3573570 • Letter: T

Question

This is what I have so far please help

Write an application that displays a series of at least 10 student ID numbers (that you have stored in an array) and ask the user to enter a test letter grade for the student. Create an Exception class named GradeException that contains a static public array of valid grade letters (‘A’, ‘B’, ’C’, ’D’, ’F’, and ’I’) which you can use to determine whether a grade entered from the application is valid. In your application, throw a GradeException and then display an appropriate message. In addition, store an ‘I’ (for Incomplete) for any student for whom an exception is caught. At the end of the application, display all the student IDs and grades. Save the files as GradeException.java and TestGrade.java.

----------

import java.util.Arrays;
import java.util.Scanner;

import javax.swing.JOptionPane;
public class TestGrade {

   public static int[] studentID= {12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
   public static String[] studentGrade= {"0","0", "0","0", "0", "0", "0", "0", "0", "0"};
   public static String[] validGrades={"A", "B", "C", "D", "F", "I"};
   public static String inString,outString = "";
   boolean isValid;


   public static void main(String[] args) throws Exception
   {
      
       String error = new String();

       Scanner input=new Scanner(System.in);
       for (int i=0; i < studentID.length; i++ )
       {
           System.out.println("Enter grade for " + studentID[i]);
           studentGrade[i]=input.next();
                  
               if (studentGrade[i] != "A" || studentGrade[i] != "B" || studentGrade[i] != "C" || studentGrade[i] != "D" || studentGrade[i] != "F" || studentGrade[i] != "I")
                  
               {
                   error= studentGrade[i] + " is invalid.";
                   studentGrade[i] = "I";
               }
       }
   }
  

}

Explanation / Answer

Since you have already tried imported essential java utilities, I am assuming you have basic knowledge of java.

So coming straight to the solution

There are two classes required
The first class is an exception class,

To create an exception class in java, we follow this pattern

class ClassName extends Exception{  

ClassName(String s){  

  super(s);  

}  

}  

So in our case GradeException.Java code will be

import java.util.*;
class GradeException extends Exception{
public GradeException(String s){
System.out.println(s);
}
}

The second class is a TestGrade
Lets see how we will do this

The ClassName should be same as file name, so we will have TestGrade Class

We need two variable to store data, ID for student ID, and grade for grading.

So the Code till here will be like

public class TestGrade{
int id;

String grade;

}

We will pass ID and Grade through constructor whenever an object is created,

So our constructor will be like

TestGrade(int id,String grade){
this.id=id;
this.grade=grade;
}

To fetch this details, we will get two getters, one for ID and the other for grade


public int getId(){
return id;
}

public String getGrade(){
return grade;
}

Now we have declared all our class objects.

To invoke, we will need a main class.

We will create a loop where we will take student id and his grade

And if it don’t contains the desired grade, we will call the exception class


public static void main(String args[]) throws Exception{
ArrayList<TestGrade> list = new ArrayList<TestGrade>();
Scanner input=new Scanner(System.in);
int StudentID;
String grade="";
String grades[] ={"A","B","C","D","F","I"};
List l=Arrays.asList(grades);

the loops starts here
for(int i=0;i<10;i++){

System.out.println("Student id: ");
StudentID=input.nextInt();   //Input student ID
System.out.println("His Grade:");
grade = input.next(); //Input student grade
if(!l.contains(grade)){ // If Grade is not from A,B,C,D,E,I get insStudentID if
new GradeException("You have entered invalid grade!Re-enter Grade:");
grade = input.next();
}

}

when the grade has been verified, we will add display the grade
list.add(new TestGrade(StudentID,grade));
System.out.println("ID Marks");
for (TestGrade test : list){
System.out.println(test.getId()+" "+test.getGrade());
}
}

so our complete code will be

GradeException.java

import java.util.*;
class GradeException extends Exception{
public GradeException(String s){
System.out.println(s);
}
}


TestGrade.Java

import java.util.*;

public class TestGrade{
int id;

String grade;
TestGrade(int id,String grade){
this.id=id;
this.grade=grade;
}
public int getId(){
return id;
}

public String getGrade(){
return grade;
}
public static void main(String args[]) throws Exception{
ArrayList<TestGrade> list = new ArrayList<TestGrade>();
Scanner input=new Scanner(System.in);
int StudentID;
String grade="";
String grades[] ={"A","B","C","D","F","I"};
List l=Arrays.asList(grades);
for(int i=0;i<2;i++){

System.out.println("Student id: ");
StudentID=input.nextInt();
System.out.println("His grade:");
grade = input.next();
if(!l.contains(grade)){
new GradeException("You have entered invalid grade!Re-enter Grade:");
grade = input.next();
}
list.add(new TestGrade(StudentID,grade));
}
System.out.println("ID Marks");
for (TestGrade test : list){
System.out.println(test.getId()+" "+test.getGrade());
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote