1 | package edu.ucsb.cs156.happiercows.strategies; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.entities.Commons; | |
4 | import edu.ucsb.cs156.happiercows.entities.UserCommons; | |
5 | import lombok.AllArgsConstructor; | |
6 | import lombok.Getter; | |
7 | ||
8 | /** | |
9 | * The CowHealthUpdateStrategies enum provides a variety of strategies for updating cow health. | |
10 | * | |
11 | * For information on Java enum's, see the Oracle Java Tutorial on <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html">Enum Types</a>, | |
12 | * which are far more powerful in Java than enums in most other languages. | |
13 | */ | |
14 | ||
15 | @Getter | |
16 | @AllArgsConstructor | |
17 | public enum CowHealthUpdateStrategies implements CowHealthUpdateStrategy { | |
18 | ||
19 | Linear("Linear", "Cow health increases/decreases proportionally to the number of cows over/under the carrying capacity.") { | |
20 | @Override | |
21 | public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows) { | |
22 |
4
1. calculateNewCowHealth : Replaced integer subtraction with addition → KILLED 2. calculateNewCowHealth : Replaced double multiplication with division → KILLED 3. calculateNewCowHealth : Replaced double subtraction with addition → KILLED 4. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$1::calculateNewCowHealth → KILLED |
return user.getCowHealth() - (totalCows - commons.getCarryingCapacity()) * commons.getDegradationRate(); |
23 | } | |
24 | }, | |
25 | Constant("Constant", "Cow health changes increases/decreases by the degradation rate, depending on if the number of cows exceeds the carrying capacity.") { | |
26 | @Override | |
27 | public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows) { | |
28 |
2
1. calculateNewCowHealth : changed conditional boundary → KILLED 2. calculateNewCowHealth : negated conditional → KILLED |
if (totalCows <= commons.getCarryingCapacity()) { |
29 |
2
1. calculateNewCowHealth : Replaced double addition with subtraction → KILLED 2. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED |
return user.getCowHealth() + commons.getDegradationRate(); |
30 | } else { | |
31 |
2
1. calculateNewCowHealth : Replaced double subtraction with addition → KILLED 2. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED |
return user.getCowHealth() - commons.getDegradationRate(); |
32 | } | |
33 | } | |
34 | }, | |
35 | Noop("Do nothing", "Cow health does not change.") { | |
36 | @Override | |
37 | public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows) { | |
38 |
1
1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$3::calculateNewCowHealth → KILLED |
return user.getCowHealth(); |
39 | } | |
40 | }; | |
41 | ||
42 | private final String displayName; | |
43 | private final String description; | |
44 | ||
45 | public final static CowHealthUpdateStrategies DEFAULT_ABOVE_CAPACITY = Linear; | |
46 | public final static CowHealthUpdateStrategies DEFAULT_BELOW_CAPACITY = Constant; | |
47 | } | |
Mutations | ||
22 |
1.1 2.2 3.3 4.4 |
|
28 |
1.1 2.2 |
|
29 |
1.1 2.2 |
|
31 |
1.1 2.2 |
|
38 |
1.1 |