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

Recently several cities in north Carolina experienced the joy of a snowfall. The

ID: 3662772 • Letter: R

Question

Recently several cities in north Carolina experienced the joy of a snowfall. The following information was recorded by WERC TV

Your task is to write a java program to compute the total amount of snowfall and the average snowfall for the cities listed above. Your program should display each city and snowfall amount and the average amount of snowfall, found and display the highest as well as the lowest also.. Solve using array system.

city snowfall Boone 2 feet Aschville 6.5 feet Winston-Salem 5.5 inches Raleigh 4 inches Fayetteville .7 inches

Explanation / Answer

import java.io.*;
class Snowfall
{
int snowfall_amount[5];
String name;

int n;       //number of cities here.
Snowfall(String city_name,int number) throws IOException

{name= city_name;

n=number;

get_snowfallamount(n)

}

public void get_snowfallamount(int n)

{snowfall_amount=new int[n];
BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
for (int i=0; i<n;i++)
{
System.out.println(“Enter the snowfall amount”);
snowfall_amount[i]=Integer.parseInt(br.readLine());


System.out.println(“”);


}

}

public void calculate_total_avg()

{ int total=0;

int average;

int lowest = snowfall_amount[0];

int highest = snowfall_amount[0];

for (int i=0;i<n;i++)

{ total+= snowfall_amount[i];

}

average=total/n;

for (i=0;i<n;i++)

{ if(snowfall_amount[i] > highest

   highest = snowfall_amount[i];

else if (snowfall_amount[i] < lowest)

   lowest = snowfall_amount[i];

}

System.out.println(“the total snowfall is :=> “+total);
System.out.println(“average snowfall is :=> “+average);
System.out.println(“highest snowfall is:=> “+highest); // highest snowfall

System.out.println(“loest snowfall is:=> “+lowest);    //lowest snowfall

}

class calc_rainfall
{
public static void main(String args[])throws IOException
{

int number1;

String city_name;

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));
System.out.println(“Enter the number of cities:=> “);
number1=Integer.parseInt(br.readLine());

Snowfall s[]=new Snowfall[number1];

for(int i=0;i<number1;i++)
{

System.out.println(“Enter city Name:=> “);
city_name=br.readLine();

System.out.println(“number of cities:=> “);
number1=br.readLine();

s[i]=new Snowfall(city_name,number1);

}

for(int i=0;i<number1;i++)
{

s[i].calculate_total_avg()

}

}

}