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:

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

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class studentClass {

   String studentFName, studentLName;
   int testScore;
   char grade;

   /**
   * @param studentFName
   * @param studentLName
   * @param testScore
   */
   public studentClass(String studentFName, String studentLName, int testScore) {
       this.studentFName = studentFName;
       this.studentLName = studentLName;
       this.testScore = testScore;
       calculateGrade();
   }

   /**
   * @return the studentFName
   */
   public String getStudentFName() {
       return studentFName;
   }

   /**
   * @return the studentLName
   */
   public String getStudentLName() {
       return studentLName;
   }

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

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

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

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

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

   /**
   * @param grade
   * the grade to set
   */
   public void setGrade(char grade) {
       this.grade = grade;
   }

   /**
   * method to set the grade
   */
   public void calculateGrade() {
       if (testScore > 90) {
           grade = 'A';
       } else if (testScore > 80) {
           grade = 'B';
       } else if (testScore > 60 && testScore <= 80) {
           grade = 'C';
       } else if (testScore > 40 && testScore <= 60) {
           grade = 'D';
       } else {
           grade = 'E';
       }
   }

   @Override
   public String toString() {
       // TODO Auto-generated method stub
       return studentFName + " " + studentLName + "\t\t" + testScore + "\t"
               + grade;
   }

}

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

public class TestStudentClass {

   /**
   *
   * @param args
   */
   public static void main(String[] args) {

       studentClass[] studentClasses = readStudent();
       System.out.println("student data reads successfully");
       writeStudent(studentClasses);
       System.out.println("student data writes successfully");
   }

   /**
   * method to write data to file
   *
   * @param studentClasses
   */
   public static void writeStudent(studentClass[] studentClasses) {

       try {

           PrintWriter printWriter = new PrintWriter(new File("Out.txt"));
           printWriter.write("Student Name\tTest Score\tGrade\n");
           for (int i = 0; i < studentClasses.length; i++) {
               printWriter.write(studentClasses[i].toString() + "\n");

           }

           int maxScore = getMaxScore(studentClasses);
           printWriter.write("Highest Test Score:" + maxScore + "\n");
           for (int i = 0; i < studentClasses.length; i++) {

               if (maxScore == studentClasses[i].getTestScore()) {

                   printWriter
                           .write(studentClasses[i].getStudentLName() + ", "
                                   + studentClasses[i].getStudentFName()
                                   + "\n");
               }

           }
           printWriter.flush();
           printWriter.close();

       } catch (Exception e) {
           // TODO: handle exception
       }
   }

   /**
   * method to read the student data
   *
   * @return
   */
   public static studentClass[] readStudent() {

       studentClass[] studentClasses = new studentClass[20];
       Scanner scanner = null;
       try {
           scanner = new Scanner(new File("Data.txt"));
           int count = 0;
           while (scanner.hasNext()) {

               studentClass studentClass = new studentClass(scanner.next(),
                       scanner.next(), scanner.nextInt());
               studentClasses[count++] = studentClass;
           }

       } catch (Exception e) {
           // TODO: handle exception
       }

       return studentClasses;

   }

   /**
   * method to get max test score
   *
   * @param studentClasses
   * @return
   */
   public static int getMaxScore(studentClass[] studentClasses) {
       int maxScore = Integer.MIN_VALUE;
       for (int i = 0; i < studentClasses.length; i++) {
           if (maxScore < studentClasses[i].getTestScore())
               maxScore = studentClasses[i].getTestScore();
       }

       return maxScore;

   }

}

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

Out.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

Out.txt

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

OUTPUT:

student data reads successfully
student data writes successfully

Add a comment
Know the answer?
Add Answer to:
THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • this is a java course class. Please, I need full an accurate answer. Labeled steps of...

    this is a java course class. Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with: (Create another file to test the class and output to the screen, not an output file) please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer. Thanks in advance. Write the definition of the class Tests such...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Input hello, I need help completing my assignment for java,Use the following test data for input...

    Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and...

    CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and outputs the top 20 names, regardless of gender. The file has the following syntax: RANK# BoyName Boy#OfBirths Boy% GirlName Girl#OfBirths Girl% You should ignore the rank and percentages. Compare the number of births to rerank. Output should go to standard out. Program 2 Write a program that reads a text file containing floating-point numbers. Allow the user to specify the source file name on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT