-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnowFallReport.java
More file actions
147 lines (108 loc) · 4.51 KB
/
SnowFallReport.java
File metadata and controls
147 lines (108 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.Scanner;
public class SnowFallReport {
public static void main(String[] args) {
intro();
Scanner console = new Scanner(System.in);
String city1 = nameofcity(console, 1);
String city2 = nameofcity(console, 2);
double ville1 = infosnow(console, city1);
double ville2 = infosnow(console, city2);
printResults(city1, ville1, city2, ville2);
compareCities(city1, ville1, city2, ville2);
}
public static void intro() {
System.out.println("This program will calculate the amount of");
System.out.println("snowfall between two cities, determining");
System.out.println("which city encountered more snow.");
System.out.println();
}
public static String nameofcity(Scanner console, int cityNumber){
System.out.print("What's the name of city #" + cityNumber + " > ");
String city = console.next();
if (city.equals("Shoreline")) {
System.out.println("Yay! I go to school in Shoreline, WA.");
}
return city;
}
public static double infosnow(Scanner console, String city){
System.out.println("\nInformation for " + city + ":");
System.out.print("\n\tHow many days did it snow for? > ");
int day = console.nextInt();
double total = 0.0;
for (int i = 1; i <= day; i++) {
System.out.print("\t\tHow many inches of snow on day " + i + "? > ");
total += console.nextDouble();
}
System.out.println("\t\t~~ Total snow fall = " + total + " inches ~~");
return total;
}
public static void printResults(String c1, double s1, String c2, double s2) {
System.out.println("\nResults:\n");
long ft1 = Math.round(s1 / 12.0);
long ft2 = Math.round(s2 / 12.0);
System.out.println("\t" + c1 + " = " + s1 + " in of snow (approx. " + ft1 + " ft)");
System.out.println("\t" + c2 + " = " + s2 + " in of snow (approx. " + ft2 + " ft)\n");
}
public static void compareCities(String c1, double s1, String c2, double s2) {
if (s1 > s2) {
System.out.println(c1 + " had more snow fall.");
} else if (s2 > s1) {
System.out.println(c2 + " had more snow fall.");
} else {
System.out.println("Both cities had the same amount of snow fall.");
}
}
}
/*
# CHANGE LOG
Entry | Summary | Change
---------------------------------------------------------------------------------------------------------------------------------------------------------------
1 |I forgot to return namecity and infosnow | I add return after looking at our Chapter 4
2 |Forgot to add concatenation | I wonder why my coded didn't work then I add "+"
3 |Forgot to add (console, 1) in the main | After, looking at chapter 4 I noticed that I needed to add (console, 1) in the main to make it work.
*/
/*
# PROGRAM OUTPUT
OUTPUT SAMPLE 1
This program will calculate the amount of
snowfall between two cities, determining
which city encountered more snow.
What's the name of city #1 > Bellingham
What's the name of city #2 > Shoreline
Yay! I go to school in Shoreline, WA.
Information for Bellingham:
How many days did it snow for? > 4
How many inches of snow on day 1? > 4.5
How many inches of snow on day 2? > 10
How many inches of snow on day 3? > 5
How many inches of snow on day 4? > 2.5
~~ Total snow fall = 22.0 inches ~~
Information for Shoreline:
How many days did it snow for? > 2
How many inches of snow on day 1? > 1
How many inches of snow on day 2? > 5.5
~~ Total snow fall = 6.5 inches ~~
Results:
Bellingham = 22.0 in of snow (approx. 2 ft)
Shoreline = 6.5 in of snow (approx. 1 ft)
Bellingham had more snow fall.
OUTPUT SAMPLE 2
This program will calculate the amount of
snowfall between two cities, determining
which city encountered more snow.
What's the name of city #1 > Shanghai
What's the name of city #2 > Seattle
Information for Shanghai:
How many days did it snow for? > 0
~~ Total snow fall = 0.0 inches ~~
Information for Seattle:
How many days did it snow for? > 3
How many inches of snow on day 1? > 3.5
How many inches of snow on day 2? > 8
How many inches of snow on day 3? > 10
~~ Total snow fall = 21.5 inches ~~
Results:
Shanghai = 0.0 in of snow (approx. 0 ft)
Seattle = 21.5 in of snow (approx. 2 ft)
Seattle had more snow fall.
*/