-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vars.java
37 lines (30 loc) · 1.11 KB
/
Vars.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
import java.util.Random;
public class Vars { //Variable object
//Instance Variables
private String letter; //variable representation
private boolean negated; //is the variable negated or not?
//Constructor
Vars(char letter) {
this.letter = String.valueOf(letter);
Random r = new Random();
int p = r.nextInt(100);
this.negated = (p > 60); //40% chance variable will be negated
}
public String toString() { //convert variable to string
if(!this.negated) {
return this.letter;
}
else {
return "\u00AC" + this.letter;
}
}
boolean equals(Vars v2) { //check if two variables are the same (same char representation and same negation status)
return((this.getLetter().equals(v2.getLetter())) && (this.isNegated() == v2.isNegated()));
}
private boolean isNegated() {
return negated;
} //return whether or not the variable is negated
String getLetter() {
return this.letter;
} //return the character representation of the variable
}