Modify the Total program so that it shows the average, not the total of the inputs. Total.java 1 import java.io.File; 2 import java.io.FileNotFoundException; 3 import java.io.PrintWriter%; 4 import...


Modify the Total program so that it shows the average, not the total of the inputs.<br>Total.java<br>1 import java.io.File;<br>2 import java.io.FileNotFoundException;<br>3 import java.io.PrintWriter%;<br>4 import java.util.Scanner;<br>6 /**<br>This program reads a file with numbers, and writes the numbers to another<br>file, lined up in a column and followed by their average.<br>9 */<br>10 public class Total<br>11 {<br>7<br>8<br>public static void main(String[] args) throws FileNotFoundException<br>{<br>// Prompt for the input and output file names<br>Scanner console = new Scanner(System.in);<br>System.out.print(

Extracted text: Modify the Total program so that it shows the average, not the total of the inputs. Total.java 1 import java.io.File; 2 import java.io.FileNotFoundException; 3 import java.io.PrintWriter%; 4 import java.util.Scanner; 6 /** This program reads a file with numbers, and writes the numbers to another file, lined up in a column and followed by their average. 9 */ 10 public class Total 11 { 7 8 public static void main(String[] args) throws FileNotFoundException { // Prompt for the input and output file names Scanner console = new Scanner(System.in); System.out.print("Input file: "); String inputFileName = System.out.print("Output file: "); String outputFileName = console.next(); 12 13 14 15 16 17 console.next(); 18 19 20 // Construct the Scanner and PrintWriter objects for reading and writing File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); PrintWriter out = new PrintWriter(outputFileName); 21 22 %3D 23 24 25 // Read the input and write the output double total = 26 27 = 0; 28 while (in.hasNextDouble()) { double value 29 30 in.nextDouble ( ); out.printf("%17.2f\n", value); value; 31 %3D 32 total = total 33 34 35 36 } out.printf("Total: %10.2f\n", total); 37 in.close(); out.close(); } 38 39 40 41 }

Jun 01, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here