Question

Java. May only use import java.util.*; and import java.io*; packages. Write a program called WeatherReporter that...

Java. May only use import java.util.*; and import java.io*; packages. Write a program called WeatherReporter that prompts the user for an input file name. reads the given file, which is in the format of CharlotteWeather2010.txt, line by line and uses the processLine() method as defined below:


public static void processLine (String line){
 

}


to output to the console the data for each day formatted as shown below:


01/01/2010 Low:  34.0 High:  48.0 Rain:  no Snow:  no
01/02/2010 Low:  24.1 High:  48.0 Rain:  no Snow:  no
...
07/05/2010 Low:  61.0 High:  97.0 Rain:  no Snow:  no
07/06/2010 Low:  64.0 High: 100.9 Rain:  no Snow:  no
07/07/2010 Low:  66.0 High: 102.0 Rain:  no Snow:  no
...
12/26/2010 Low:  28.4 High:  36.0 Rain: yes Snow: yes
12/27/2010 Low:  21.2 High:  37.4 Rain:  no Snow:  no
...


CharlotteWeather2010.txt

Should be in the format of:

YYYYMMDD Average(F) High(F) Low(F) Fog/Rain/Snow/Hail/Thunder/Tornado
20100101   44.2   48   34   100000
20100102   29.9   48   24.1   000000
20100103   24.2   32   18   000000
20100104   26.2   36   17.1   000000
20100105   26.9   36   17.1   000000
20100106   29.1   41   18   000000
20100107   32.4   48   19   000000
20100108   35.1   48   20.1   010000
20100109   25.9   35.6   19.4   000000
20100110   28   37.4   19.4   000000
20100111   27.6   45   15.1   000000
20100112   34.9   45   16   000000
20100113   31.4   44.6   19.4   000000
20100114   37.5   57.2   24.8   000000
20100115   42.9   63   25.2   000000
20100116   44   63   28.2   000000
20100117   53.6   68   30.2   010000
20100118   50.9   68   39.9   100000
20100119   47.8   66.2   35.6   000000
20100120   51.2   66   35.1   000000
20100121   40.2   64.9   37   010000
20100122   37.9   41   37   010000

...etc.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// WeatherReporter.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;

public class WeatherReporter
{

public static void manipualteLine(String readLine) throws ParseException
{
String[] tkns = readLine.split("\\s+");

SimpleDateFormat iFormat = new SimpleDateFormat("yyyymmdd");
SimpleDateFormat outFormat = new SimpleDateFormat("mm/dd/yyyy");
String resultDate = outFormat.format(iFormat.parse(tkns[0]));
String min = tkns[3];
String max = tkns[2];
String snowRate = tkns[4].charAt(2) == '1' ? "yes": "no";
String rainRate = tkns[4].charAt(1) == '1' ? "yes": "no";

StringBuilder output = new StringBuilder();
output.append(resultDate).append(" ")
.append("Low: ").append(min).append(" ")
.append("High: ").append(max).append(" ")
.append("Rain: ").append(rainRate).append(" ")
.append("Snow: ").append(snowRate);

System.out.println(output);
}

public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the file name: ");

String fileName = input.nextLine();
try
{
BufferedReader buffRead = new BufferedReader(new FileReader(fileName));
String readLine;
while ((readLine = buffRead.readLine()) != null)
{
manipualteLine(readLine);
}

} catch (IOException e)
{
e.printStackTrace();
} catch (ParseException pe)
{
pe.printStackTrace();
}
}
}


Terminal ER ..- (%) (0:46, 48%) ) 1:38 AM ubuntu HomeworkLib.sh WeatherReporter java x ubuntu@ayushv: ~/Desktop/codes/HomeworkLibsoluti

Add a comment
Know the answer?
Add Answer to:
Java. May only use import java.util.*; and import java.io*; packages. Write a program called WeatherReporter that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT