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

mcessing Produce the following output which should be sent to a text file and pr

ID: 3787671 • Letter: M

Question

mcessing Produce the following output which should be sent to a text file and printed. Use appropriate field widths with floating point numbers formatted to two decimals using DecimalFormat class and other techniques learned in Chapter 3 Do not use printf function on this assignments should work for any valid nonempty data set do not assume each data set contains dates for December. the names are capitalized. Reporter code is the first letter ofthe first name followed by first letter of last name. manually edit the ou it must be code. Use your in an name in output. Weather Watch by Your Name Town Date Tempo Direction wind speed Reporter BANGOR 12/10/16 34.70 2.50 12/10/16 33.65 2.70 SS BANGOR 12/11/16 32.00 2.30 CALAIS 12/11/16 35.10 1.90 CALAIS 12/11/16 35.75 W 2.00 BANGOR 12/12/16 31.90 2.80 BANGOR 12/13/16 28.50 2.10 12/13/16 26.85 2.00 12/13/16 26.90 2.10 CALAIS 12/13/16 33.15 2.700 ORONO 12/14/16 28.60 E 3.10 IS BANGOR 12/14/16 31.75 E 3.00 overall Average Temperature: 31.57 overall Average wind speed: 2.43 Number of readings: CALAIS 3 Historical Averages January 24.92 February 32.700 March 45.91 April 52.00 June 73.55 July 78.63 August 77.59 September 68.40 October 55.700 November 45.75 December 36.33 Difference between this December from historical average is -4.76 Include minimally the following methods. PREPOST commands are mandatory. 1. write a static method which is passed a month number as a String ("01 "12") and returns the month name, 2. write a static method which is passed the weather watcher name and returns a code of first letter of first name followed by first letter of last name.

Explanation / Answer

import java.io.*;
import java.util.List;
import javax.swing.*;
import java.util.ArrayList;
import java.util.*;


class Main
{
public static String[] readdata(String filename)
{
List<String> list = new ArrayList<String>();
try(BufferedReader in = new BufferedReader(new FileReader(filename)))
{
String str;
  
while((str = in.readLine()) != null) //use Exception handling here
{
list.add(str);
}
}
catch (FileNotFoundException e)
{
System.out.println("Error");
}
String[] arr = list.toArray(new String[0]);
return arr;
}
  
public static String initials(String fullname)
{
/*Read a full name and return initials */
char first = fullname.split(" ")[0].charAt(0);
char last = fullname.split(" ")[1].charAt(0);
String init = Character.toString(first)+Character.toString(last);
return init;
}
  
public static String month_name(String number)
{
/*Convert month number string to month name string */
int month = Integer.parseInt(number);
String monthName;
switch (month)
{
case 1: monthName = "January";
break;
case 2: monthName = "February";
break;
case 3: monthName = "March";
break;
case 4: monthName = "April";
break;
case 5: monthName = "May";
break;
case 6: monthName = "June";
break;
case 7: monthName = "July";
break;
case 8: monthName = "August";
break;
case 9: monthName = "September";
break;
case 10: monthName = "October";
break;
case 11: monthName = "November";
break;
case 12: monthName = "December";
break;
default: monthName = "Invalid month";
break;
}
return monthName;
}
  
public static void main(String[] args)
{
String myname = "John Doe";
String[] weather_arr = readdata("weather.txt"); //Read lines of weather.txt to String array
String[] avg_arr = readdata("averages.txt"); //Read lines of averages.txt to String array
int w_lines = weather_arr.length;
int avg_lines = avg_arr.length;
System.out.println("Weather Watch by " + myname +" ");
String[] header = {"Town", "Date", "Temp", "Direction", "Wind Speed", "Reporter"};
for(String elem: header)
{
System.out.println(elem + " ");
}
int i=0;
int j=0;
for(i=0; i<w_lines;i++)
{
for(j=0; j<5; j++)
{
System.out.println(weather_arr[i].split(" ")[j].toUpperCase() + " "); //Split at tabs.
}
System.out.println(initials(weather_arr[i].split(" ")[j]));
}
float totaltemp = 0;
float totalwind = 0;
for(i=0; i<w_lines;i++)
{
totaltemp += Float.parseFloat(weather_arr[i].split(" ")[2]);
totalwind += Float.parseFloat(weather_arr[i].split(" ")[4]);
}
float avg_temp = totaltemp/w_lines;
float avg_wind = totalwind/w_lines;
System.out.println(" Overall Average Temprature " + avg_temp);
System.out.println(" Overall Average Wind Speed " + avg_wind);
  
int ban=0;
int oro=0;
int cal=0;
for(i=0; i<w_lines;i++)
{
if(weather_arr[i].split(" ")[0].equals("Bangor"))
{
ban = ban+1;
}
else if(weather_arr[i].split(" ")[0].equals("Calais"))
{
cal = cal+1;
}
else if(weather_arr[i].split(" ")[0].equals("Orono"))
{
oro = oro+1;
}
}
  
System.out.println(" Number of Readings : ");
System.out.println(" BANGOR : " + ban);
System.out.println(" ORONO : " + oro);
System.out.println(" CALAIS : " + cal);
  
System.out.println(" Hostorical Averages : ");
String m;
for(i=0; i<12;i++)
{
m = Integer.toString(i+1);
System.out.println(month_name(m) + " " + avg_arr[i].split("\s")[1]);
}
float diff = avg_temp - (Float.parseFloat(avg_arr[11].split("\s")[1]));
System.out.println("Difference between this december from historical averages is : " + diff);
}
}