-
Notifications
You must be signed in to change notification settings - Fork 0
/
Witch.java
69 lines (64 loc) · 2.08 KB
/
Witch.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
/**
* @author jvogt33
* @version 1.00
*/
public class Witch extends TrickOrTreater implements Robbable {
private String signatureCackle;
/**
* Constructor for new Witch.
* @param name the name of this Witch
* @param age the age of this Witch
* @param numCandy the amount of candy the Witch will start out with
* @param signatureCackle String representing the cackle the Witch will produce in trickOrTreat()
*/
public Witch(String name, int age, int numCandy, String signatureCackle) {
super(name, age, numCandy);
if (signatureCackle == null || signatureCackle.trim().equals("")) {
this.signatureCackle = "Bwahaha";
} else {
this.signatureCackle = signatureCackle;
}
}
/**
* No-Arg constructor for new Witch.
* Produces default values "Maleficent", 7, 0, "Bwahaha"
*/
public Witch() {
this("Maleficent", 7, 0, "Bwahaha");
}
/**
* Overrides TrickOrTreater.trickOrTreat().
* This implementation prints string containing "{signatureCackle}! I'll get you my pretty!",
* then runs gainCandy() with candy amount 3
*/
@Override
public void trickOrTreat() {
System.out.println(String.format("%s! I'll get you my pretty!", signatureCackle));
this.gainCandy(3);
}
/**
* Overrides Robbable.beRobbed().
* A witch can lose up to 6 candy in a robbery, depending on the amount they
* have before it occurs.
* @return the amount of candy lost as an int
*/
@Override
public int beRobbed() {
int c = this.loseCandy(6);
return c;
}
/**
* Overrides TrickOrTreater.compareTo().
* @param o the other TrickOrTreater to compare to
* @return int representing natural order of Witches.
*/
@Override
public int compareTo(TrickOrTreater o) {
int x = super.compareTo(o);
if (x == 0 && o instanceof Witch) {
x = Integer.compare(this.signatureCackle.length(),
((Witch) o).signatureCackle.length());
}
return x;
}
}