Question: import java.io . File; import java.io . FileNotFoundException; import java.util.Scanner; public class TemperatureProcessor { / / this method converts a single Kelvin temperature to Celsius
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
public class TemperatureProcessor
this method converts a single Kelvin temperature to Celsius
private static double kcdouble temp
return temp Celsius.ZEROKINCELSIUS;
this method converts a single Celsius temperature to Kelvin
private static double ckdouble temp
return temp Celsius.ZEROKINCELSIUS;
this method converts a single Celsius temperature to Fahrenheit
private static double fcdouble temp
return temp ;
this method converts a single Fahrenheit temperature to Celsius
private static double cfdouble temp
return temp ;
public static void mainString args
System.out.printlnThis program processes temperature data from a file and reports statistics";
try Scanner input new ScannerSystemin
System.out.printEnter the name of the temperature file: ;
String fileName input.nextLine;
Scanner fileScanner new Scannernew FilefileName;
Celsius temps new Celsius;
int validTempCount readTemperatureFilefileScanner temps;
printTemperatureDatafileName temps, validTempCount;
fileScanner.close;
catch FileNotFoundException e
System.err.printlnFile not found. Please check the file name and try again.";
public static int readTemperatureFileScanner reader, Celsius temps
int count ;
while readerhasNextLine && count temps.length
String line reader.nextLine;
double celsiusTemp processTempLineline;
if celsiusTemp Celsius.ZEROKINCELSIUS
tempscount new CelsiuscelsiusTemp;
return count;
public static double processTempLineString line
try
String parts line.trimsplits;
if partslength
return Celsius.ZEROKINCELSIUS ;
double value Double.parseDoubleparts;
String unit partstoLowerCase;
switch unit
case k:
return kcvalue;
case c:
return value;
case f:
return fcvalue;
default:
return Celsius.ZEROKINCELSIUS ;
catch NumberFormatException e
return Celsius.ZEROKINCELSIUS ;
public static void printTemperatureDataString fileName, Celsius temps, int count
if count
System.out.printlnNo valid temperatures found in this file: fileName;
return;
double totalC totalK totalF ;
int aboveAverageCount ;
for int i ; i count; i
double c tempsigetC;
totalC c;
totalK ckc;
totalF cfc;
double avgC totalC count;
double avgK totalK count;
double avgF totalF count;
for int i ; i count; i
if tempsigetC avgC
aboveAverageCount;
System.out.printlnTemperature data from the file: fileName;
System.out.printfAverage in Celsius: fn avgC;
System.out.printfAverage in Kelvin: fn avgK;
System.out.printfAverage in Fahrenheit: fn avgF;
System.out.printlnNumber of temperatures above average: aboveAverageCount;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
