-
Notifications
You must be signed in to change notification settings - Fork 1
/
Happy.java
88 lines (73 loc) · 1.98 KB
/
Happy.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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Happy.java
//grace nguyen
//march 10, 2022
import java.io.*;
public class Happy extends Attribute implements Serializable{
public static void main(String[] args){
//class testing
Happy grace = new Happy(0);
grace.decrement();
System.out.println(grace.getStatus());
grace.setStatus(100D);
System.out.println(grace.getStatus());
} //end main
//constructors
public Happy() {
super("Happy Meter", 5d);
} //end constructor
public Happy(double status) {
super("Happy Meter", status);
} //end construcotr
//methods meant to be used with other classes (Plant.java)
public Boolean isDead() {
Boolean isDead = false;
if(this.status.equals(0)) {
isDead = true;
} //end if
return(isDead);
} //end isDead
public Double dailyMoney() {
//returns the money that the plant 'gives' the owner
//based on the happy meter
//note: there is no negative money values
//note: exponential growth (slower than quadratic)
if(this.status < 1D) {
return(0D);
}else{
double money = java.lang.Math.log10(this.status);
money = money * 0.75;
return(money);
} //end if-else
} //end dailyMoney
//implement inherited abstract classes
public void setStatus(Double status) {
if(status < 0D) {
this.status = 0D;
}else{
this.status = status;
} //end if-else
} //end setStatus
public void decrement() {
if(this.status >= 1D) {
this.status--;
}else{
this.status = 0D;
} //end if
} //end decrement
public void decrement(double amount) {
//polymorphic behavior
if(this.status >= amount) {
this.status = this.status - amount;
}else{
this.status = 0D;
} //end if
} //end decrement
public void increment() {
this.status++;
} //end increment
public void increment(double amount) {
//polymorphic behavior
//no max on happy status
this.status = this.status + amount;
} //end increment
} //end class def