-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeather.java
More file actions
46 lines (39 loc) · 1.14 KB
/
Weather.java
File metadata and controls
46 lines (39 loc) · 1.14 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
import java.util.Random;
/**
* A model for the weather.
*
* @author Saathveekan Satheshkumar and Manik Aggarwal
* @version 2022.03.02 (2)
*/
public class Weather {
// The probability for each weather event
private double SUNNY_PROBABILITY = 0.4;
private double RAINY_PROBABILITY = 0.4;
private double HURRICANE_PROBABILITY = 0.01;
// True if there is daylight.
private boolean isDay;
public Weather() {
}
/**
* Randomly sets the weather for each step (day and night).
* @return the new weather to be set.
*/
public String setWeather() {
Random rand = Randomizer.getRandom();
if (isDay && rand.nextDouble() <= SUNNY_PROBABILITY) {
return "Sunny";
} else if (rand.nextDouble() <= RAINY_PROBABILITY) {
return "Rainy";
} else if (rand.nextDouble() <= HURRICANE_PROBABILITY) {
return "Hurricane";
}
return "Cloudy";
}
/**
* Changes the time of day it is.
* @param isDay boolean which is true when there is daylight.
*/
public void timeOfDay(boolean isDay) {
this.isDay = isDay;
}
}