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

THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please h

ID: 3844393 • Letter: T

Question

THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS.

Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, 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

Program must contain 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 the following 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 as follow:

6) You MUST use the "Data.txt" file as input data file and "Out.txt" as a output result file.

Input "Data.txt" file must have information in the following manner:

Duckey Donald 85
Goof Goofy 89
Brave Balto 93
Snow Smitn 93
Alice Wonderful 89
Samina Akthar 85
Simba Green 95
Donald Egger 90
Brown Deer 86
Johny Jackson 95
Greg Gupta 75
Samuel Happy 80
Danny Arora 80
Sleepy June 70
Amy Cheng 83
Shelly Malik 95
Chelsea Tomek 95
Angela Clodfelter 95
Allison Nields 95
Lance Norman 88

Output result file "Out.txt" must have information in the following manner:

Student Name           Test Score Grade
Donald, Duckey               85      B
Goofy, Goof                  89      B
Balto, Brave                 93      A
Smitn, Snow                  93      A
Wonderful, Alice             89      B
Akthar, Samina               85      B
Green, Simba                 95      A
Egger, Donald                90      A
Deer, Brown                  86      B
Jackson, Johny               95      A
Gupta, Greg                  75      C
Happy, Samuel                80      B
Arora, Danny                 80      B
June, Sleepy                 70      C
Cheng, Amy                   83      B
Malik, Shelly                95      A
Tomek, Chelsea               95      A
Clodfelter, Angela           95      A
Nields, Allison              95      A
Norman, Lance                88      B

Highest Test Score: 95
Students having the highest test score:
Green, Simba
Jackson, Johny
Malik, Shelly
Tomek, Chelsea
Clodfelter, Angela
Nields, Allison

7) Other than declaring variables and opening the input and output files, the function main() should only be a collection of function calls.

8) Comment your code and use meaningful or mnemonic variable names

Student Name Test Score Grade Donald, Duckey 85 Goofy, Goof 89 Balto Brave 93 Smit n, Snow 93 wonderful, Alice 89 85 Akthar Samina. Green Simba 95 Egger, Donald 90 86 Brown Deer Jackson Johny 95 75 Gupta, Happy, Samuel 80 Arora Danny June sleepy 83 Malik, Shelly 95 Tomek Chelsea 95 Clodfelter Angela Nields, Allison 95 88 Norman, Lance Highest Test Score: 95 Students having the highest test score: Green Simba Jackson Johny Malik Shelly Tomek, Chelsea Clodfelter Angela Nields. Allison

Explanation / Answer

Solution: See the code below:

1. StudentClass class: StudentClass.java

------------------------------------------

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
*
* StudentClass class
*/
public class StudentClass {

    class Student {

        private String studentFName; //first name of student
        private String studentLName; //last name of student
        private int testScore; //test score of student
        private char grade; //grade of student

        /**
         * Constructor
         *
         * @param studentFName
         * @param studentLName
         * @param testScore
         * @param grade
         */
        Student(String studentFName, String studentLName, int testScore, char grade) {
            this.studentFName = studentFName;
            this.studentLName = studentLName;
            this.testScore = testScore;
            this.grade = grade;
        }

        /**
         * @return student first name
         */
        public String getStudentFName() {
            return studentFName;
        }

        /**
         * @return student last name
         */
        public String getStudentLName() {
            return studentLName;
        }

        /**
         * @return student test score
         */
        public int getTestScore() {
            return testScore;
        }

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

        /**
         * sets student grade
         *
         * @param grade
         */
        public void setGrade(char grade) {
            this.grade = grade;
        }

    }
    Student[] students; //array to store students
    int numStudents = 20; //number of students in class

    /**
     * Default constructor
     */
    public StudentClass() {
        numStudents=20;
        students = new Student[numStudents];
    }
    /**
     * Constructor
     *
     * @param numStudents
     */
    public StudentClass(int numStudents) {
        this.numStudents = numStudents;
        students = new Student[numStudents];
    }

    /**
     * reads student data from file
     *
     * @param filename
     */
    void readStudentData(String filename) throws FileNotFoundException, IOException {
        File file = new File(filename);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line;
        int i = 0;
        while ((line = reader.readLine()) != null) {
            Scanner in = new Scanner(line);
            String firstName = in.next();
            String lastName = in.next();
            int testScore = in.nextInt();
            Student student = new Student(firstName, lastName, testScore, ' ');
            students[i] = student;
            i++;
            in.close();
        }
        numStudents = i;
        reader.close();
    }

    /**
     * assigns grades to each student based on his/her test score
     */
    void assignGrades() {
        for (int i = 0; i < numStudents; i++) {
            int score = students[i].getTestScore();
            if (score >= 90) {
                students[i].setGrade('A');
            } else if (score >= 80 && score < 90) {
                students[i].setGrade('B');
            } else if (score >= 70 && score < 80) {
                students[i].setGrade('C');
            } else {
                students[i].setGrade('D');
            }
        }
    }

    /**
     * @return highest test score
     */
    int findHighestTestScore() {
        int score = students[0].getTestScore();
        for (int i = 1; i < numStudents; i++) {
            if (students[i].getTestScore() > score) {
                score = students[i].getTestScore();
            }
        }
        return score;
    }

    /**
     * displays students with highest test score
     */
    void displayStudentsWithHighestTestScore() {
        int score = findHighestTestScore();
        for (int i = 0; i < numStudents; i++) {
            if (students[i].getTestScore() == score) {
                System.out.println(students[i].getStudentLName() + "," + students[i].getStudentFName());
            }
        }
    }

    void writeStudentData(String filename) throws IOException {
        File file = new File(filename);
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.write("Student Name Test Score Grade ");
        for (int i = 0; i < numStudents; i++) {
            String data = students[i].getStudentLName() + ","
                    + students[i].getStudentFName() + " "
                    + students[i].getTestScore() + " "+
                    students[i].getGrade() + " ";
            writer.write(data);
        }
        writer.close();
    }
}

--------------------------------------

2. main() function:

-------------------------------------

import java.io.IOException;

/**
*
* Studentgrades class
*/
public class Studentgrades {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        String infile="./Data.txt";
        String outfile="./Out.txt";
      
        StudentClass studentClass = new StudentClass();
        studentClass.readStudentData(infile);
        studentClass.assignGrades();
        studentClass.writeStudentData(outfile);
        System.out.println("Highest Test Score:"+studentClass.findHighestTestScore());
        System.out.println("Students having highest test score:");
        studentClass.displayStudentsWithHighestTestScore();
    }
  
}

--------------------------------

3. Data.txt:

--------------------------

Duckey Donald 85
Goof Goofy 89
Brave Balto 93
Snow Smitn 93
Alice Wonderful 89
Samina Akthar 85
Simba Green 95
Donald Egger 90
Brown Deer 86
Johny Jackson 95
Greg Gupta 75
Samuel Happy 80
Danny Arora 80
Sleepy June 70
Amy Cheng 83
Shelly Malik 95
Chelsea Tomek 95
Angela Clodfelter 95
Allison Nields 95
Lance Norman 88


--------------------------------

4. Out.txt:

-----------------------------------

Student Name       Test Score       Grade
Donald,Duckey       85       B
Goofy,Goof       89       B
Balto,Brave       93       A
Smitn,Snow       93       A
Wonderful,Alice       89       B
Akthar,Samina       85       B
Green,Simba       95       A
Egger,Donald       90       A
Deer,Brown       86       B
Jackson,Johny       95       A
Gupta,Greg       75       C
Happy,Samuel       80       B
Arora,Danny       80       B
June,Sleepy       70       C
Cheng,Amy       83       B
Malik,Shelly       95       A
Tomek,Chelsea       95       A
Clodfelter,Angela       95       A
Nields,Allison       95       A
Norman,Lance       88       B

------------------------------------------

5. Output:

----------------------------------

Highest Test Score:95
Students having highest test score:
Green,Simba
Jackson,Johny
Malik,Shelly
Tomek,Chelsea
Clodfelter,Angela
Nields,Allison

----------------------------------------