Question

Please code in JAVAGenerate an output1 that contains the capital case name + average score. Quiz1.txt Ricky 80 Becky 79 Nicky 90 Quiz2.txt Ricky

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


/** Java program that reads two input files called Quiz1.txt and Quiz2.txt and then
* then find the average of the quiz scores and write the name in upper case letters
* and average quiz score to the Output.txt file * */

//ReadQuiz.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class ReadQuiz
{
   public static void main(String[] args) throws IOException
   {
         
       String file1="Quiz1.txt";
       String file2="Quiz2.txt";
       String outFileName="Output.txt";
      
       try
       {
           //Open files for reading data from Quiz1.txt and Quiz2.txt
           Scanner filereader1=new Scanner(new File(file1));
           Scanner filereader2=new Scanner(new File(file2));
           //Open file for writing to file Output.txt
           FileWriter filewriter=new FileWriter(new File(outFileName), false);
           //read until end of file
           while(filereader1.hasNextLine() && filereader2.hasNextLine())
           {
               //Split the data by space and store in string array
               String data1[]=filereader1.nextLine().trim().split(" ");
               String data2[]=filereader2.nextLine().trim().split(" ");
               //Get name
               String name=data1[0];
               double quiz1=Double.parseDouble(data1[1]);
               double quiz2=Double.parseDouble(data2[1]);
               //calculate average quiz score
               double average=(quiz1+quiz2)/2.0;
               //Write to file ,Output.txt
               filewriter.write(String.format("%s %.2f\r\n", name.toUpperCase(),average));
           }
           //close the input and output streams
           filereader1.close();
           filereader2.close();
           filewriter.close();
           System.out.println("Ouptut written to Output.txt file");
                  
       }
       catch (FileNotFoundException e)
       {
           System.out.println("File not found");
       }
   }//end of main method
} //end of the class

Sample Input files

O X - Help Quiz1 - Notepad File Edit Format View Ricky 80 Becky 79 Nicky 90

- Help 0 x Quiz2 - Notepad File Edit Format View Ricky 90 Becky 88 Nicky 100

Sample Output:

Output written to Output.txt file

Output.txt

O X - Help Output - Notepad File Edit Format View RICKY 85.00 BECKY 83.50 NICKY 95.00

Note: Make sure all the input and source code files in the same directory.

Add a comment
Know the answer?
Add Answer to:
Please code in JAVA Generate an output1 that contains the capital case name + average score....
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
  • Find the errors in the following code: / / Warning! This code contains ERRORS! switch (score)...

    Find the errors in the following code: / / Warning! This code contains ERRORS! switch (score) { case (score > 90): grade = 'A'; break; case(score > 80): grade = 'B'; break; case(score > 70): grade = 'C'; break; case (score > 60): grade = 'D'; break; default: grade = 'F'; } *Submit in Java format

  • Write a program that uses the keys(), values(), and/or items() dict methods to find statistics about...

    Write a program that uses the keys(), values(), and/or items() dict methods to find statistics about the student grades dictionary. Find the following: Print the name and grade percentage of the student with the highest total of points. Also print the grade as per the below grading scale 90 to 100         A 80 to 89           B 70 to 79           C 60 to 69           D Below 60         F Find the average score of each assignment. Use the following data:...

  • Java code ABOVE AVERAGE 40 Input Standard input Output Standard output Topic Array & Array Processing...

    Java code ABOVE AVERAGE 40 Input Standard input Output Standard output Topic Array & Array Processing Problem Description Understanding how to interpret test scores is a valuable skill for every teacher. That's because test score interpretation enables teachers to understand how their students' performance for each tests of the course. Average test score is one of the indicators to determine the class performance for the test. For each test, we need to calculate the average score and determine the percentage...

  • Create a java project with the name Assignment3YourLastName in the folder COMP3110AssignmentsYourLastName Part-1 (use a nested-if-else...

    Create a java project with the name Assignment3YourLastName in the folder COMP3110AssignmentsYourLastName Part-1 (use a nested-if-else statement) Add a static method with the name gradeLetter. This method will ask the user to enter an integer score and display the grade letter based on the rules: Score range Grade letter 90—100 A 80—89 B 70—79 C 60—69 D 0—59 F Part-2 (use a while statement) Add a static method with the name CalculateGrade. This method will ask the user to enter...

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

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

  • Do men score lower on average compared to women on their statistics test? test scores of...

    Do men score lower on average compared to women on their statistics test? test scores of nineteen randomly selected male statistics students and twenty-eight randomly selected female statistics students are shown below. Assume Equal Variances. Male:  86, 83, 74, 76, 80, 63, 94, 91, 65, 95, 57, 91, 84, 85, 79, 76, 87, 94, 64 Excel Female:  88, 99, 82, 90, 65, 99, 76, 93, 93, 69, 70, 89, 96, 83, 74, 77, 90, 91, 100, 78, 76, 100, 78, 84, 100,...

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

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