-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatistics.java
31 lines (26 loc) · 928 Bytes
/
Statistics.java
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
package a4;
/** An instance contains the probabilities that a person gets a flu<br>
* and a person becomes immune in a time step.
*
* @author Mshnik, revised by Gries. */
public class Statistics {
/** Probability of contagion. In range [0, 1]. */
private double contagionChance;
/** Probability of immunization. In range [0, 1]. */
private double immunizationChance;
/** Constructor: an instance with contagion probability cp and <br>
* immunization probability ip. <br>
* Precondition: 0 <= cp, ip <= 1. */
public Statistics(double cp, double ip) {
contagionChance= cp;
immunizationChance= ip;
}
/** = (new random number) < (the probability of contagion). */
public boolean fluSpreadsToPerson() {
return Math.random() < contagionChance;
}
/** = (new random number) < (the probability of becoming immune). */
public boolean personBecomesImmune() {
return Math.random() < immunizationChance;
}
}