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
  • Write a javascript program that asks the user to enter five test scores. The program should...

    Write a javascript program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage—This method should accept five test scores as arguments and return the average of the scores. determineGrade—This method should accept a test score as an argument and return a letter grade for the score,

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Round the average...

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

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

  • Write a program that asks the user to enter five test scores. The program should display...

    Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program: calcAverage—This function should accept five test scores as arguments and return the average of the scores. determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale: Score Letter Grade...

  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

  • Write a program that will calculate your letter grade at the end of the semester for...

    Write a program that will calculate your letter grade at the end of the semester for CSIS130. Your program will read an input file that shall contain all the tests scores and lab scores for the semester, and the input file data should be in the following format: full name of student Test1 Score (0…100), Test2 Score (0..100) , Final Exam Score (0..100), Total Number of Labs: N NLab Scores (0=Fail, 1=Pass) [You will have N lab scores each separated...

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

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