Question: public class CityWeatherV2 { // private instance variables - three arrays private String[] months; private double[] temperature; private double[] precipitation;

public class CityWeatherV2 {
// private instance variables - three arrays
private String[] months;
private double[] temperature;
private double[] precipitation;
// constructor with parameters
public CityWeatherV2(String[] m, double[] t, double[] p) {
months = m;
temperature = t;
precipitation = p;
}
// setters and getters for each private instance variable
//Getters
public String[] getMonth(String[] months) {
return months;
}
public double[] getTemperature(double[] temperature) {
return temperature;
}
public double[] getPrecipitation(double[] precipitation) {
return precipitation;
}
//Setters
public void setMonth(String[] m) {
months = m;
}
public void setTemperature(double[] t) {
temperature = t;
}
public void setPrecipitation(double[] p) {
precipitation = p;
}
// method to calculate the average of temperature
public double calcAverageAnnualTemperature(double[] t) {
double total = 0;
double average = 0.0;
//for loop to add the values
for (int i = 0; i total = total + t[i];
}
average = total / t.length;
return average;
}
// method to calculate total precipitation array
public double calcTotalAnnualPrecipitation(double[] p) {
double total = 0;
//for loop to add the values
for (int i = 0; i total = total + p[i];
}
return total;
}
// method to calculate temperature in Celsius (current index of temperature array passed as a parameter) - to be completed in 6.02
public double calcFahrenheitToCelsuis(double celsius, double fahrenheit) {
celsius = ((fahrenheit - 32) * 5) / 9;
return celsius;
}
// method to calculate precipitation in centimeters (current index of precipitation array passed as a parameter) - to be completed in 6.02
public double calcInchesToCentimeters(double inches, double centimeters) {
centimeters = inches * 2.54;
return centimeters;
}
}
the above is the object class
_
_
_
_
import java.util.Scanner;
public class CityWeatherTesterV2
{
// method to print results (formatting output will be done in 6.02)
public String formattedTable() {
//Output: display table of weather data including average and total
System.out.println();
System.out.println(" Weather Data");
System.out.println(" Location: " + city +", " + state);
System.out.println("Month Temperature (" + temperatureInput + ") Precipitation (" + precipitationInput + ")");
System.out.println();
System.out.println("***************************************************");
//for( int index = 0; index //{
// use printf to format
//}
System.out.println("Average: " + " Total: ");
}
public static void main (String [ ] args)
{
//Declare and initialize variables
Scanner in = new Scanner(System.in); //will be used in 6.02
String city = "Orlando"; //choose a city from the table provided
String state = "Florida"; //choose a city from the table provided
String [] month = {"Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec." };
double [] orlandoTemperature = {60.9, 62.6, 67.4, 71.5, 81.2, 82.4, 82.5, 75.3, 68.8, 63.0};//complete initialization of months array
double [] orlandoPrecipitation = {2.4, 2.4, 3.5, 2.4, 3.7, 7.4, 7.2, 6.3, 5.8, 2.7, 2.3, 2.3};
String tempLabel = "F"; //initialize to F
String precipLabel = "in."; //initialize to in
//input to decide F/C and in/cm - to be completed in 6.02
System.out.print("Choose the temperature scale (F = Fahrenheit, C = Celsius): ");
String temperatureInput = in.next();
System.out.print("Choose the precipitation scale (i = inches, c = centimeters): ");
String precipitationInput = in.next();
System.out.println();
//instantiate AnnualWeatherV1 object
CityWeatherV2 annualWeatherData = new CityWeatherV2(month, orlandoTemperature, orlandoPrecipitation);
//conditions & method call to convert temp, if needed - to be completed in 6.02
annualWeatherData.calcFahrenheitToCelsuis();
if(temperatureInput.equalsIgnoreCase("F")) {
for(double tempData: orlandoTemperature) {
System.out.println(tempData);
}
}
else if(temperatureInput.equalsIgnoreCase("C")) {
for(double tempData: orlandoTemperature) {
System.out.println(tempData);
}
}
//conditions & method call to convert prec, if needed - to be completed in 6.02
annualWeatherData.calcInchesToCentimeters();
if(precipitationInput.equals("i")) {
for(double precData: orlandoPrecipitation) {
System.out.println(precData);
}
}
else if(precipitationInput.equals("c")) {
for(double precData: orlandoPrecipitation) {
System.out.println(precData);
}
}
//method call to calculate the average temperature
annualWeatherData.calcAverageAnnualTemperature();
//method call to calculate the total precipitation
annualWeatherData.calcTotalAnnualPrecipitation();
//method call to print results (hint: Need parameters for month, temperature, precipitation arrays, data labels and the average temperature, total precipitation variables)
formattedTable();
}//end main
}//end class
the above is the tester class
Modify the CityWeatherV1 class to display weather data as Fahrenheit or Celsius and inches or centimeters per the user's request. Conversion between units should be done as needed. The output should be precisely formatted. Note: This is a two-part assignment. You should have completed the first part in the previous lesson. CityWeatherV1 CityWeatherTesterV1 1. Create a new project called 06.02 Weather Data in the Mod06 Assignments folder. 2. Create an object class called CityWeatherV2 in the newly-created folder. A. Copy the previous CityWeatherV1 class code and paste it into the new object class. B. Be sure to change the class name. C. You will need to create the following non-static methods to convert the temperature to Celsius or the precipitation to centimeters. Based on the user's input, these methods may or may not be used. Remember, 5/9 = 0 but 5.0/9 = 0.5555 I. A method to convert the temperature to Celsius II. A method to convert the precipitation to centimeters 3. Create a client class called CityWeather Tester V2 in the same folder. A. Copy the previous CityWeather TesterV1 class code and paste it into the new client class. B. Provide the user with the option to choose a temperature scale of Fahrenheit or Celsius. Do the same for the precipitation scale and the choices of inches or centimeters. The user input should not be case sensitive. C. Complete the static method to print the output in a neatly formatted table. You will need to add a method header and complete the printf() statement in the starter code. The columns of String data should be left aligned. The columns of numeric data should be aligned on the decimal point. Display numeric values to one decimal place. The average temperature and total precipitation should now be included in this method. 4. Your instructor will paste in data from a different location to test your program. So you should also test the program with an alternate set of data as a precaution. Leave both sets in the source code, but comment out one location. 5. When you complete this assignment, turn it in for a grade. Expected Output: When your program runs correctly, the output should resemble the following screen shot: BlueJ: Terminal Window -... Options Choose the temperature scale (F Fahrenheit, C Celsius): f Choose the precipitation scale (i = inches, c = centimeters): c Weather Data Location: Tallahassee, Florida. Month Temperature (F) Precipitation (cm.). Jan. 51.8 13.7 Feb. 54.8 11.7 Mar. 61.1 16.5 Apr. 66.4 9.1 May 74.4 12.7 Jun. 80.4 17.5 Jul. 82.4 20.3 Aug. 82.1 17.8 Sep. 78.9 12.7 Oct. 69.1 8.4 Nov. 60.4 9.9 Dec. 53.7 10.4 Average: 68.0 Annual: 160.81
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
