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

Processing: Produce the following output which should be sent to a text file and

ID: 3787025 • Letter: P

Question

Processing: 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 printffunction on this assignment, should work for nonempty data set; do not assume each data set contains dates for December. Town names are capitalized. Reporter code is the first letter of the first name followed by first letter of the last name. Do manually edit he output file in any way, it must be produced by code. Use your name in output. Weather watch by Your Name Town BANGOR Temp 12/10/16 34.70 Direction Wind Speed Reporter 2.50 12/10/16 33.65 2.70 12/11/16 32.000 2.30 CALAIS 12/11/16 35.10 W 1.900 CALAIS 12/11/16 35.75 2.00 BANGOR 12/12/16 31.9e N 2.80 BANGOR 12/13/16 28.50 N 2.100 12/13/16 26.85 N 2.00 12/13/16 26.90 2.10 IS CALAIS 12/13/16 33.15 N 2.70 12/14/16 3.10 12/14/16 31.75 3.00 overall Average Temperature 31.57 Overall Average wind speed: 2.43 Number of re adings CALAIS 3 Historical Averages: January 24.92 February 32.700 45.91 April 52.00 73.55 July 78.63 August 77.59 September 68.40 October 45.75 December 36.33 Difference between this December from historical average is -4.76 Include minimally the following methods. PRE/POST commands are mandatory. 1. Write a static method which is passed a month number as a String 12") and returns the month 2. write a static method which is passed the weather watcher name and retums a code of first letter of first name followed by first letter of last name.

Explanation / Answer

import java.util.*;
import java.io.*;
import java.text.DecimalFormat;

public class CheggTemp{
   public static void main(String args[]) throws IOException {
       File f = new File("weather.txt");
       String path = "";
       Map<String, Integer> unique_names = new HashMap<String, Integer>();
       double[] month = new double[12];
       DecimalFormat df = new DecimalFormat("00.00");
       DecimalFormat df2 = new DecimalFormat("0.00");

       if (f.exists()){
           path = f.getAbsolutePath();
       }
       else{
           System.out.println("File doesn't exist");
       }
       BufferedReader br = new BufferedReader(new FileReader(path));
       String currLine;
       System.out.println("Weather Watch by Your Name");
       System.out.println("Town Date Temp Direction Wind Speed Reporter ");
       int i;
       double temp_val=0,temp_sum=0;
       double wind_sum=0;
       double wind_val;
       StringBuffer sb = new StringBuffer();
       int month_ind;
       int count = 0;
       while((currLine = br.readLine())!= null){
           count++;
           String[] result = currLine.split("\s+");
           System.out.print(result[0]);
           Integer freq = unique_names.get(result[0]);
           unique_names.put(result[0], (freq == null) ? 1 : freq + 1);
           System.out.print(" "+result[1]);
           temp_val = Double.parseDouble(result[2]);
           temp_sum += temp_val;
           month_ind = Integer.parseInt(result[1].substring(0,2));
           month[month_ind-1] += temp_val;
           System.out.print(" "+df.format(temp_val));
           System.out.print(" "+result[3]);
           wind_val = Double.parseDouble(result[4]);
           wind_sum += wind_val;
           System.out.print(" "+df2.format(wind_val));
           System.out.print(" "+Character.toUpperCase(result[5].charAt(0)));
           System.out.println(Character.toUpperCase(result[6].charAt(0)));
       }
       System.out.println();
       System.out.println("Overall Average Temperature: "+df.format(temp_sum/count));
       System.out.println("Overall Average Wind Speed: "+df.format(wind_sum/count));
       System.out.println();
       System.out.println("Number of readings:");
       for(String va: unique_names.keySet()){
           System.out.print(va +" ");
           System.out.println(unique_names.get(va));
       }
       f = new File("averages.txt");
       if (f.exists()){
           path = f.getAbsolutePath();
       }
       else{
           System.out.println("File doesn't exist");
       }
       System.out.println();
       System.out.println("Historical Averages :");
       br = new BufferedReader(new FileReader(path));
       double value;
       while((currLine = br.readLine())!= null){
           String[] result = currLine.split("\s+");
           System.out.print(result[0]);
           value = Double.parseDouble(result[1]);
           System.out.println(" "+ df.format(value));
       }
       for(int z=0;z<month.length;z++){
           if(month[z]>0){
               System.out.print("Difference Between this");
               System.out.print(month_se(Integer.toString(z)));
               System.out.print("from Historical average is");
               System.out.print((temp_sum/count) - (month[z]));
           }
       }
   }
   public static String month_se(String str){
       String[] temp = {"January","February","March","May","June","July","August","September","October","November","December"};
       int month_ind = Integer.parseInt(str.substring(0,2));
       return temp[month_ind-1];
   }
}

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