Question

use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

use  JOptionPane to display output

Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program. The data that you will need is stored in the accompanying file call test1.txt. You will have to open the file and read the scores into the program one at a time. Output: The output should include the following: o The number of students who took the test. o The number of students who received each of the letter grades A, B, C, D, F. o The overall average for the class. Output should be displayed in a single Message box. This is the test1.txt file 80 82 77 44 35 77 88 89 93 94 72 83 85 75 75 87 86 94 93 58 68

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

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thanks.

GradeBatch.java

package fileIO;


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

import javax.swing.JOptionPane;

public class GradeBatch {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       //loading name of file
       File file = new File("test1.txt"); //reading data from this file
       Scanner reader;
       try {
           //read file using scanner
           reader = new Scanner(file);
           int count = 0;
           int grades[] = {0,0,0,0,0};
           double total =0;
           while(reader.hasNextLine()){
               //read line
               int temp = reader.nextInt();
              
               if(temp>=90) grades[0]++;
               else if(temp>=80) grades[1]++;
               else if(temp>=70) grades[2]++;
               else if(temp>=60) grades[3]++;
               else grades[4]++;
               total +=temp;
               count++;
               //write the data
           }
           StringBuffer output = new StringBuffer();
           output.append("Total number of students : "+count+"\n");
           for(int i=0;i<5;i++){
               char g = (char) ('A'+i);
               output.append("Total number of students got grade "+g+": "+grades[i]+"\n");
           }
           output.append("Overall average "+total/count);
           JOptionPane.showMessageDialog(null, output.toString());
       } catch (FileNotFoundException e) {
           System.out.println("file not found");
       }
       sc.close();
   }


}

F# - 1 - 1 - - - D GradeBatch.java test 1.txt X 180 82 77 44 35 77 88 89 93 94 72 83 85 75 75 87 86 94 93 58 68 A Message Tot

Add a comment
Know the answer?
Add Answer to:
use  JOptionPane to display output Can someone please help write a program in Java using loops, not...
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++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Write a program to calculate students’ average test scores and their grades. You may assume the...

    Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • 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 FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

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

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

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

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

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

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