Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am asking this question again as the first time that I asked this question noo

ID: 3864253 • Letter: I

Question

I am asking this question again as the first time that I asked this question noone responded. Can someone please answer the question below.

You are given a data file (quarterback_stats.txt) that includes the starting quarterbacks stats in 2016 regular season. The data includes the player's first name, last name, team, games played, passing attempts, passing completions, yards, touchdowns, and ratings.

Write a Java program that reads the data from the data file, calculates the passing completion rate (completions/attempts) for each quarterback, then scores the results in another file (quarterback_results.txt). I like to use jGrasp. Also would be helpful to write in the System.out. and not stuff like <cout> as I dont know what that is and maybe a screenshot of the program.

The program should also calculate the total TD's and the average completion rate of all players.

The output file should be formatted correctly (2 decimal places, alignment, blank lines, and etc...)

Here is a image of the (quarterback_stats.txt) file as I do not know how to add attachments to this question: https://gyazo.com/03230145914d81128222c8065d350e1a

Here is a image of the input file of (quarterback_stats.txt): https://gyazo.com/3af0796696edf19c743d08ea13671baa

Here is a image of the output file that you should get at the end: https://gyazo.com/6a9886421221d2ab0e770505762e2256

Explanation / Answer

Here is the code for above scenario:

package demo;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter;

public class Quarterback {
   public static void main(String[] args) throws FileNotFoundException, IOException {
       int avg =0;
       int totalTDs =0;
       int completionAvg =0;
       int playerCount =0;
       int totalComp =0;
      
      
       File fout = new File("quarterback_results.txt");
       FileOutputStream fos = new FileOutputStream(fout);
     
       BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
       try (BufferedReader br = new BufferedReader(new FileReader("quarterback_stats.txt"))) {
       String line;
       int firstLine=0;
       while ((line = br.readLine()) != null) {
           if(firstLine==0){
               String firstLineOut = line+" CMP. Rate";
               bw.write(line);
               bw.newLine();
               firstLine++;
           }
           else{
               String[] arr = line.split("\s+");
               avg = Integer.parseInt(arr[5])/Integer.parseInt(arr[4]);
               String outputData = line+" "+avg;
               bw.write(line);
               bw.newLine();
               totalTDs = totalTDs + Integer.parseInt(arr[7]);
               totalComp = totalComp + Integer.parseInt(arr[5]);
           }
       }
       //Counting number of players
       LineNumberReader lnr = new LineNumberReader(new FileReader(new File("quarterback_stats.txt")));
       lnr.skip(Long.MAX_VALUE);
       playerCount = lnr.getLineNumber() -1;
       lnr.close();
      
       completionAvg = totalComp / playerCount ;
      
      
       String totalTdsOut = "Total TDs:"+totalTDs;
       bw.write(totalTdsOut);
       bw.newLine();
      
       String compAvgOut = "Completion average of all players:"+completionAvg;
       bw.write(compAvgOut);
       bw.newLine();
       }
       bw.close();
   }
}