Question: import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers to another file, lined up

 import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program

reads a file with numbers, and writes the numbers to another file,

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

/** This program reads a file with numbers, and writes the numbers to another file, lined up in a column and followed by their average. */ public class Total { 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 = console.next(); System.out.print("Output file: "); String outputFileName = console.next();

// 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); // Read the input and write the output // only modify the below code // /* Your code goes here */ double total = 0;

while (in.hasNextDouble()) { double value = in.nextDouble(); out.printf("%17.2f ", value); total = total + value; /* Your code goes here */ } out.printf("Total: %10.2f ", total); /* Your code goes here */ in.close(); out.close(); } }

\begin{tabular}{l|l} CHALLENGE & 8.5.2: Modify the program to show average rather than total. \end{tabular} Modify the Total program so that it shows the average, not the total of the inputs. \begin{tabular}{l|l} CHALLENGE & 8.5.2: Modify the program to show average rather than total. \\ ACTIVITY & 8. \end{tabular} 460140.2737408.9x3zqy7 Modify the Total program so that it shows the average, not the total of the inputs

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!