-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeather.java
More file actions
executable file
·60 lines (51 loc) · 2.31 KB
/
Copy pathWeather.java
File metadata and controls
executable file
·60 lines (51 loc) · 2.31 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
import java.util.*;
class Weather {
// All possible weather conditions
Rain[] rainList = {new Rain("Clear", 0), new Rain("Clear", 0), new Rain("Clear", 0), new Rain("Clear", 0), new Rain("Clear", 0), new Rain("Light Rain", 50), new Rain("Heavy Rain", 100), new Rain("Hail", 100)};
Cloud[] cloudList = {new Cloud("Clear", 0), new Cloud("Clear", 0), new Cloud("Clear", 0), new Cloud("Clear", 0), new Cloud("Clear", 0), new Cloud("Mostly Sunny", 10), new Cloud("Partly Cloudy", 20), new Cloud("Partly Cloudy", 20), new Cloud("Partly Cloudy", 20), new Cloud("Partly Cloudy", 20), new Cloud("Cloudy", 70), new Cloud("Cloudy", 70), new Cloud("Cloudy", 70), new Cloud("Overcast", 100)};
Wind[] windList = {new Wind("Calm", 0), new Wind("Calm", 0), new Wind("Calm", 0), new Wind("Calm", 0), new Wind("Light Breeze", 25), new Wind("Light Breeze", 25), new Wind("Light Breeze", 25), new Wind("Gusty", 80), new Wind("Storm Force", 100)};
Random rand = new Random();
UserInterface ui = new UserInterface();
public Rain establishRainForecast() {
int rainChance = rand.nextInt(rainList.length);
Rain rainForecast = rainList[rainChance];
return rainForecast;
}
public Cloud establishCloudForecast(){
int cloudChance = rand.nextInt(cloudList.length);
Cloud cloudForecast = cloudList[cloudChance];
return cloudForecast;
}
public Wind establishWindForecast(){
int windChance = rand.nextInt(windList.length);
Wind windForecast = windList[windChance];
return windForecast;
}
public void printWeatherForecast(Rain rain, Cloud cloud, Wind wind) {
rain.printRainForecast();
cloud.printCloudForecast();
wind.printWindForecast();
}
public boolean willLaunchSucceed(int rainChance, int cloudChance, int windChance) {
// Aka: The "Will You Die" Calculator
boolean launchStatus = true;
int diceRoll = rand.nextInt(100);
int sumChance = rainChance + cloudChance + windChance;
if (rainChance == 100) {
launchStatus = false;
} else if (cloudChance == 100) {
launchStatus = false;
} else if (windChance == 100) {
launchStatus = false;
} else if (diceRoll < rainChance) {
launchStatus = false;
} else if (diceRoll < cloudChance) {
launchStatus = false;
} else if (diceRoll < windChance) {
launchStatus = false;
} else if (diceRoll < sumChance) {
launchStatus = false;
}
return launchStatus;
}
}