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

hi! Please do the programming code in the programming language java: Please foll

ID: 3839062 • Letter: H

Question

hi! Please do the programming code in the programming language java: Please follow these directions: Write a program which:

Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.
Student data should be stored in an instance of class variable of type studentClass, which has four components: StudentFName, studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use an array of 20 elements of type studentClass.
SPECIFIC REQUIREMENTS
Your program must contain at least the following methods:
1. A method to read the students’ data into the array 2. A method to assign the relevant grade to each student 3. A method to find the highest test score 4. A method to print the names of the students having the highest test score. 5. Your program must output each student’s name in this form: last name followed by a comma, followed by a space, followed by the first name, the name must be left justified; you should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score,6. Other than declaring variables and opening the input and output files, the function main() should only be a collection of function calls. 7. Comment your code and use meaningful or mnemonic variable names. 8. You must use the “Data.txt” file provided; failure to use this file and not adhere to the requirements will severely affect your grade.

1. No infinite loops, examples include: a. for(;;) b. while(1) c. while(true) d. do{//code}while(1); 2. No break statements to exit loops

Explanation / Answer


public class Student {
   private String fName;
   private String lName;
   private int score;
   private char grade;
  
   public Student(String fName,String lName,int score) {
       this.fName = fName;
       this.lName = lName;
       this.score = score;
       if(score>90)
           grade='A';
       else if(score>80)
           grade='B';
       else if(score>70)
           grade='C';
       else if(score>50)
           grade='D';
       else
           grade='F';
   }
   public Student() {
      
   }
   public String getfName() {
       return fName;
   }

   public void setfName(String fName) {
       this.fName = fName;
   }

   public String getlName() {
       return lName;
   }

   public void setlName(String lName) {
       this.lName = lName;
   }

   public int getScore() {
       return score;
   }

   public void setScore(int score) {
       this.score = score;
   }

   public char getGrade() {
       return grade;
   }

   public void setGrade(char grade) {
       this.grade = grade;
   }
  
   public String toString(){
       String str = "";
       str += ""+fName+" "+lName+", "+score+" ";
       return str;
   }
}


import java.io.File;
import java.util.Scanner;


public class StudentTest {

   public static void main(String[] args) {
       Student[] students = readStudents("Data.txt");
       displayStudents(students);
       Student stu = getMax(students);
       System.out.println("Student Have Max Score : "+stu);
   }
   public static Student[] readStudents(String filename){
       Student[] students = new Student[20];
       try{
           Scanner sc = new Scanner(new File(filename));
           int i=0;
           while(sc.hasNext()){
               String fn = sc.next();
               String ln = sc.next();
               int score = sc.nextInt();
               Student stu = new Student(fn, ln, score);
               students[i] = stu;
               i++;
               if(i>=20)
                   break;
           }
       }
       catch(Exception e){
          
       }
       return students;
   }
   public static void displayStudents(Student[] students){
       for(int i=0; i<students.length; i++){
           if(students[i]!=null)
               System.out.println((i+1)+". "+students[i]);
           else
               System.out.println((i+1)+". null ");
       }
   }
  
   public static Student getMax(Student[] students){
       int scr =0;
       Student stu= null;
       for(int i=0; i<students.length; i++){
           if(students[i]!=null && students[i].getScore()>scr){
               stu = students[i];
               scr = students[i].getScore();
           }
       }
       return stu;
   }
}