I need help writing a JAVA program that will read students n

I need help writing a JAVA program that will read 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) I have to use an array of 20 elements of type studentClass.

The program must contain at least the following functions:
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. The 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. Moreover, other than declaring variables and opening the input and output files, the function main() should only be a collection of function calls.

Solution

public class Student {

   String fName, lName;
   int testScore;
   char grade;

   /**
   * @param fName
   * @param lName
   * @param testScore
   * @param grade
   */
   public Student(String fName, String lName, int testScore) {
       this.fName = fName;
       this.lName = lName;
       this.testScore = testScore;
       this.grade = \' \';
   }

   /**
   * @return the fName
   */
   public String getfName() {
       return fName;
   }

   /**
   * @param fName
   * the fName to set
   */
   public void setfName(String fName) {
       this.fName = fName;
   }

   /**
   * @return the lName
   */
   public String getlName() {
       return lName;
   }

   /**
   * @param lName
   * the lName to set
   */
   public void setlName(String lName) {
       this.lName = lName;
   }

   /**
   * @return the testScore
   */
   public int getTestScore() {
       return testScore;
   }

   /**
   * @param testScore
   * the testScore to set
   */
   public void setTestScore(int testScore) {
       this.testScore = testScore;
   }

   /**
   * @return the grade
   */
   public char getGrade() {
       return grade;
   }

   /**
   * @param grade
   * the grade to set
   */
   public void setGrade() {

       if (testScore > 80) {
           grade = \'A\';
       } else if (testScore > 60 && testScore <= 80) {
           grade = \'B\';
       } else if (testScore > 40 && testScore <= 60) {
           grade = \'C\';
       } else {
           grade = \'D\';
       }
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return lName + \", \" + fName + \", \" + testScore + \", \" + grade;
   }

}

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

public class TestStudentScore {
   public static void main(String[] args) throws FileNotFoundException {

       Student[] students = new Student[20];

       students = readStudentsData();
       students = assignGrade(students);
       printHighestScore(students);
       printStudent(students);

   }

   /**
   * method to read the student data
   *
   * @return
   * @throws FileNotFoundException
   */
   public static Student[] readStudentsData() throws FileNotFoundException {
       Student[] students = new Student[20];

       String fName, lName;
       int testScore;
       char grade;
       Scanner scanner = new Scanner(new File(\"student.txt\"));
       for (int i = 0; i < students.length; i++) {

           fName = scanner.next();

           lName = scanner.next();

           testScore = scanner.nextInt();
           students[i] = new Student(fName, lName, testScore);
       }

       return students;

   }

   /**
   * method to assign the relevant grade to each student
   *
   * @param students
   * @return
   */
   public static Student[] assignGrade(Student[] students) {
       for (int i = 0; i < students.length; i++) {
           students[i].setGrade();
       }

       return students;
   }

   /**
   * method to find the highest test score
   *
   * @param students
   * @return
   */
   public static int getHighestScore(Student[] students) {
       int maxScore = Integer.MIN_VALUE;
       for (int i = 0; i < students.length; i++) {
           if (students[i].getTestScore() > maxScore) {

               maxScore = students[i].getTestScore();
           }
       }

       return maxScore;
   }

   /**
   * method to print the names of the students having the highest test score
   *
   * @param students
   * @return
   */
   public static void printHighestScore(Student[] students) {
       int maxScore = getHighestScore(students);
       for (int i = 0; i < students.length; i++) {
           if (students[i].getTestScore() == maxScore) {

               System.out.println(students[i]);
           }
       }

   }

   /**
   * method to print the names of the students
   *
   * @param students
   * @return
   */
   public static void printStudent(Student[] students) {

       for (int i = 0; i < students.length; i++) {

           System.out.println(students[i]);

       }

   }

}

student.txt

srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50
pavan kumar 89
srinu vasu 56
rajesh kumar 50

OUTPUT:

kumar, pavan, 89, A
kumar, pavan, 89, A
kumar, pavan, 89, A
kumar, pavan, 89, A
kumar, pavan, 89, A
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C
kumar, pavan, 89, A
vasu, srinu, 56, C
kumar, rajesh, 50, C

I need help writing a JAVA program that will read students’ names followed by their test scores. The program should output each student’s name followed by the t
I need help writing a JAVA program that will read students’ names followed by their test scores. The program should output each student’s name followed by the t
I need help writing a JAVA program that will read students’ names followed by their test scores. The program should output each student’s name followed by the t
I need help writing a JAVA program that will read students’ names followed by their test scores. The program should output each student’s name followed by the t
I need help writing a JAVA program that will read students’ names followed by their test scores. The program should output each student’s name followed by the t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site