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

Write a program that collects an input filename and an output filename. The inpu

ID: 3656814 • Letter: W

Question

Write a program that collects an input filename and an output filename. The input file contains lines with two double numbers per line. Write the maximum of each line in the input file to the output file (one average per line). Use a Scanner to collect the filenames from the user. Test your program using numbers . txt for input. After completion, my program produces max. txt with contents: Modify your program so that it prints the maximum of each line even if there are not exactly two numbers on each hue of the input file. Assume there is at least one number per line. Test using moreNumbers . txt.

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class main
{public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter input file name: ");
String inputFile = input.nextLine();
System.out.print("Enter output file name: ");
String outputFile = input.nextLine();
String buffer;
double max,n;
int i;
try{
File file1 = new File(inputFile);
Scanner fileIn = new Scanner(file1);
PrintWriter out = new PrintWriter(outputFile);
while(fileIn.hasNextLine()){
buffer=fileIn.nextLine();
String[] numbers=buffer.split("\s+");     //multiple whitespaces
max=Double.parseDouble(numbers[0]);
for(i=1;i<numbers.length;i++)
    {n=Double.parseDouble(numbers[i]);
           if(n>max)
                  max=n;
    }
out.println(max);   
}
fileIn.close();
out.close();
}
catch(IOException e)
    {System.out.println("Problem with data");}
System.out.println("Processing complete.");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote