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