-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.java
96 lines (80 loc) · 3.27 KB
/
Event.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
89
90
91
92
93
94
95
96
//Whatcom Community College - Winter 2019
//CS240 Data Structures and Algorithm Analysis
//Professor Ryan Parsons
//AUTHORS: Adib Thaqif, Andrew Jacobi, Donald Strong, and Micah Miller
//
//Constructor class to create an Event object. This object will be used as part of the Choices Game project.
public class Event {
//Initialize variables
public String aspect, text;
public int reward, punishment;
public boolean played;
//CONSTRUCTOR. Takes in String text which will describe the specific event, and two int values that determine
//the percentage added (for the reward) or deducted (for the punishment) from the running total.
//Throws an IllegalArgumentException if the reward is negative and/or the punishment is positive.
public Event(String aspect, String text, int reward, int punishment) {
this.aspect = aspect;
this.text = text;
if (reward < 0) {
throw new IllegalArgumentException("Rewards must be positive!");
} else {
this.reward = reward;
}
if (punishment > 0) {
throw new IllegalArgumentException("Punishments must be negative!");
} else {
this.punishment = punishment;
}
}
//CONSTRUCTOR. Returns an empty Event object.
public Event() {
}
//toString() method that prints out the Event's text, followed by both the reward and punishment values.
public String toString() {
return "Event: " + text +"\nReward: +" + reward + "% \tPunishment: " + punishment + "%";
}
//add() method that takes in a String for the text, a positive int for the reward, and a negative value
//for the punishment. This method allows you to add all three of these fields to an empty Event object.
//Throws an IllegalStateException if the Event object is not null when trying to add these fields.
//Throws an IllegalArgumentException if the reward value is negative, or if the punishment value is positive.
public void add(String data, int newReward, int newPunishment) {
if (!isEmpty()) {
throw new IllegalStateException("You can only add to an empty Event object!");
} else if (newReward < 0) {
throw new IllegalArgumentException("Rewards must be positive!");
} else if (newPunishment > 0) {
throw new IllegalArgumentException("Punishments must be negative!");
} else {
this.text = data;
}
this.reward = newReward;
this.punishment = newPunishment;
}
//delete() method that deletes the data in the text, reward, and punishment field's and returns an empty Event
//object.
public void delete() {
this.aspect = null;
this.text = null;
this.reward = 0;
this.punishment = 0;
}
public String getAspect() {
return this.aspect;
}
public int getReward() {
return this.reward;
}
public int getPunishment() {
return this.punishment;
}
public String getEvent() {
return this.text;
}
public int getEventHashCode() {
return this.text.hashCode();
}
//isEmpty() method to check if the text field is null. If null, return true; else return false.
public boolean isEmpty() {
return (this.text == null);
}
} //End of Class