Question

Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the students name, average (rounded to 1 decimal place) and a letter grade for each student. After processing all student test grades the program should display the overall average (the average of all student averages) rounded to 1 decimal place. DO NOT USE ARRAYS, USE ONLY METHODS THAT ARE MENTIONED BELOW AS PER YOUR REQUIREMENT . Use the following methods in your program to accomplish these tasks, you may use more methods however the ones listed below are mandatory: . studentAverage: This method will have parameters for the number of test scores for one student. It will return the numeric average for that student as a real number determineGrade: This method will have a parameter for the numeric average grade of one student and will return a letter grade for the student, based on the following grading scale: Average Letter Grade . e 90-100 A . 80-89 B . 70-79 60-69 D Below 60 F overallAverage: This method will have parameters for the sum of the numeric averages for all students and the number of students and will return the average of all students as a real number . . Be sure to create your data file first before executing your program. Your data file should have at least 5 records of student data. SAMPLE DATA Brandon 907090 808Ω etc. SAMPLE OUTPUT Name Average Letter Grade Javed 92.4A Alan 86.2 B Brandon 82.0 B The average test grade is: 86.7
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Kindly let me know if more corrections are needed.

Please give a thumps up if you like the answer

Program



import java.util.*;
import java.io.*;
import java.text.DecimalFormat;

public class FileStudent {

  
    public static void main(String[] args) throws IOException
   
    {
     
Scanner stdin = new Scanner(new FileReader("studentsgrade.txt"));
  
int num_test;

double classAverage=0.0,sumAvg=0.0;
int count=0;

num_test=stdin.nextInt();
System.out.println("Name\tAverage\tLetter Grade");
        while(stdin.hasNextLine()) {
            sumAvg+=calculateAverage(stdin,num_test);
            count++;
           
        }
        classAverage=overallAverage(sumAvg,count);
        DecimalFormat value = new DecimalFormat("#.#");
      System.out.println("\nThe average test grade is "+value.format(classAverage));
     
stdin.close();

}

    public static double calculateAverage(Scanner stdin,int num_test)
    {
        double sum=0,test_score;
        double avg=0.0;
        String stud_name=stdin.next();
       
        for(int i=0;i<num_test;i++)
        {
            test_score=stdin.nextInt();
            sum+=test_score;
        }
        avg=sum/num_test;
        String grade=determineGrade(avg);
        System.out.println(stud_name+"\t"+avg+"\t"+grade);
        return avg;
    }
    public static String determineGrade(double average)
    {
        if(average>=90)
            return "A";
        else if(average>=80)
            return "B";
        else if(average>=70)
            return "C";
        else if(average>=60)
            return "D";
        else
            return "F";
    }
    public static double overallAverage(double sumAvg,int num_stud)
    {
       double classAverage=sumAvg/num_stud;
       return(classAverage);
    }
}

Output

Name Average Letter Grade
Javed 92.4 A
Alan 86.2 B
Brandon 82.0 B

The average test grade is 86.9

studentsgrade.txt

5
Javed 100 90 80 100 92
Alan 85 75 91 95 85
Brandon 90 70 90 80 80

Add a comment
Know the answer?
Add Answer to:
Write a Java program that reads a file until the end of the file is encountered....
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
  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

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

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

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

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