Write a Java Snow Fall Program: A Write a program that can be used by a ski reso
ID: 3684527 • Letter: W
Question
Write a Java Snow Fall Program: A Write a program that can be used by a ski resort to keep track if local snow conditions for one week. It should have two seven-element arrays to store the date and number of inches of snow. First, the program should ask the user to enter the name of the month. Then, it should have the user enter dates (dates does not need to be in sequential order) and corresponding snow fall. Once data is entered, store them in two arrays mentioned above. Then, the program should produce a report for the week with following information. Use arrays to store snowfall and corresponding dates.
a)Highest snow fall.
b)Average snow fall.
Here is a sample report
Snow Report December
=================
Date Snow Fall
1 89.00
5 67.98
12 56. 83
13 12.45
16 100.67
20 78.76
25 34.65
Height snow fall is 100.67 on 16th and the average snow fall is 62.90
Explanation / Answer
java program:
import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;
public class SnowFall {
public static void main(String[] args) {
double[][] snow = new double[7][2];
double temp1;
int max;
Scanner scan = new Scanner(System.in);
System.out.println("Enter month name:");
String month = scan.next();
for (int i = 0; i < snow.length; i++) {
System.out.print(" Enter date:");
snow[i][0] = scan.nextDouble();
System.out.print(" Enter snow fall in inches:");
snow[i][1] = scan.nextDouble();
}
for (int i = 0; i < snow.length; i++) {
for (int j=i+1;j<snow.length;j++) {
if(snow[i][0]>snow[j][0]){
temp1=snow[i][0];
snow[i][0]=snow[j][0];
snow[j][0]=temp1;
temp1=snow[i][1];
snow[i][1]=snow[j][1];
snow[j][1]=temp1;
}
}
}
max=0;
double sum=snow[0][1];
for(int i=1;i<snow.length;i++){
if(snow[max][1]<snow[i][1])
max=i;
sum+=snow[i][1];
}
System.out.println("snow report"+month);
System.out.println("=================");
System.out.println("Date SnowFall");
for (int i = 0; i < snow.length; i++) {
System.out.println(snow[i][0]+" "+snow[i][1]);
}
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("High sonw fall is:"+snow[max][1]+" on "+snow[max][0]+"th and average snow fall is:"+df.format(sum/snow.length));
}
}
output:
run:
Enter month name:
December
Enter date:26
Enter snow fall in inches:45.36
Enter date:12
Enter snow fall in inches:85.25
Enter date:7
Enter snow fall in inches:74
Enter date:9
Enter snow fall in inches:96.69
Enter date:5
Enter snow fall in inches:25.36
Enter date:1
Enter snow fall in inches:75.35
Enter date:31
Enter snow fall in inches:100.67
snow reportDecember
=================
Date SnowFall
1.0 75.35
5.0 25.36
7.0 74.0
9.0 96.69
12.0 85.25
26.0 45.36
31.0 100.67
High sonw fall is:100.67 on 31.0th and average snow fall is:71.81
BUILD SUCCESSFUL (total time: 1 minute 11 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.