-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
96 lines (82 loc) · 2.05 KB
/
Player.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
/**
* Player.java: Player class that holds thier name and initial money amount.
* <p>
* <b>Discription</b>:<br /b> This player class will be used to keep the player name and running
* money amount through out multiple games. It will also have methods specific to
* a Player such as Hit or Stay.
* </p>
*
* @author Adolfo Sanpedro Gante
* @version 1.0
*/
public class Player {
//Instance variables
private int money = 0; //The Player money amount
private String name= ""; //The Players name
/**
* Player with a name and money amount.
* @param name The players name.
* @param money The playes money amount.
*/
public Player (String name, int money) {
this.name = name;
this.money = money;
}
/**
* No Arg-Constructor
*/
public Player () {
}
//Getters and Setters
/**
* Gets a players money amount.
* @return an amount of money
*/
public int getMoney() {
return this.money;
}
/**
* Gets a players name.
* @return a name
*/
public String getName() {
return this.name;
}
/**
* Sets a players money amount.
* @param money the amount of money a player has
*/
public void setMoney(int money) {
this.money = money;
}
/**
* Sets a players name
* @param name a name
*/
public void setName(String name) {
this.name = name;
}
//toString and Equals
/**
* Prints a players name and money amount
* @return Players name and money amount
*/
public String toString() {
return ( "Name: " + name + ", Money: " + money);
}
/**
* Checks if two players are equal to each other
* @param anObject A Player object
* @return true or false
*/
public boolean equals(Object anObject) {
if (anObject == null) {
return false;
}
if (getClass() != anObject.getClass()) {
return false;
}
Player anotherPlayer = (Player) anObject;
return (name.equals(anotherPlayer.getName()) && money == anotherPlayer.getMoney());
}
}