Question: create an input file for the following java code, allowing the scanners to accept the input file to use as example inputs - - -
create an input file for the following java code, allowing the scanners to accept the input file to use as example inputs
import java.io;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class WeatherData
protected String date;
protected int highTemperature;
protected int lowTemperature;
protected String weatherCondition;
public WeatherDataString date, int highTemperature, int lowTemperature, String weatherCondition
this.date date;
this.highTemperature highTemperature;
this.lowTemperature lowTemperature;
this.weatherCondition weatherCondition;
class DailyWeatherData extends WeatherData
public DailyWeatherDataString date, int highTemperature, int lowTemperature, String weatherCondition
superdate highTemperature, lowTemperature, weatherCondition;
class WeatherDataAnalyzer
private ArrayList weatherDataList;
private File dataFile new Fileweatherdata.txt;
public WeatherDataAnalyzer
weatherDataList new ArrayList;
loadDataFromFile;
private void loadDataFromFile
if dataFileexists
try BufferedReader reader new BufferedReadernew FileReaderdataFile
String line;
while line reader.readLine null
String data line.split;
catch IOException e
System.out.printlnFailed to read from file: egetMessage;
public void addWeatherDataWeatherData weatherData
weatherDataList.addweatherData;
appendDataToFileweatherData;
private void appendDataToFileWeatherData weatherData
try BufferedWriter writer new BufferedWriternew FileWriterdataFile true
writer.writeweatherDatadate weatherData.highTemperature weatherData.lowTemperature weatherData.weatherCondition;
writer.newLine;
catch IOException e
System.out.printlnFailed to write to file: egetMessage;
Existing methods for showing statistics...
public class Main
public static void mainString args
WeatherDataAnalyzer analyzer new WeatherDataAnalyzer;
Scanner scanner new ScannerSystemin;
while true
System.out.printlnEnter the date YYYYMMDD:;
String date scanner.nextLine;
System.out.printlnEnter the high temperature:";
int highTemp scanner.nextInt;
System.out.printlnEnter the low temperature:";
int lowTemp scanner.nextInt;
scanner.nextLine; consume the newline character
System.out.printlnEnter the weather condition sunny rainy, cloudy, windy:;
String condition scanner.nextLine;
DailyWeatherData dailyData new DailyWeatherDatadate highTemp, lowTemp, condition;
analyzer.addWeatherDatadailyData;
System.out.printlnDo you want to quit? yesno;
String quit scanner.nextLine;
if yesequalsIgnoreCasequit
break;
System.out.printlnWould you like to pull statistics? days or no;
String statsOption scanner.nextLine;
switch statsOption
case :
analyzer.showStatsForLastDays;
break;
case :
analyzer.showStatsForLastDays;
break;
case :
analyzer.showStatsForLastDays;
break;
default:
System.out.printlnContinuing data collection...";
scanner.close;
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
