-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
118 lines (85 loc) · 2.57 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class Player {
private Name name;
private Date dob;
private int moneyBalance;
public Player() {
makePlayer();
}
public Player(Name name, Date dob, int moneyBalance) {
setName(name);
setDob(dob);
setMoneyBalance(moneyBalance);
}
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public int getMoneyBalance() {
return moneyBalance;
}
public void setMoneyBalance(int moneyBalance) {
String message = "";
String prompt = "Type Here";
//if money available is negative ask for a positive value
while(moneyBalance <= 0) {
//make sure that the answer is a valid input
try {
moneyBalance = Integer.parseInt(JOptionPane.showInputDialog("Enter a POSITIVE money balance", prompt));
if(moneyBalance < 1) {
JOptionPane.showMessageDialog(null, "Please enter a Positive integer.");
}
}catch(java.lang.NumberFormatException e) {
message = "Please enter a valid integer";
JOptionPane.showMessageDialog(null, message);
}
}
this.moneyBalance = moneyBalance;
}
public String toString() {
//format for money balance
DecimalFormat df = new DecimalFormat("#,###,###$");
String message = "";
//player information displayed
message += "Player's Name: "+name+"\n";
message += "Player's Date of Birth: "+dob+"\n";
message += "Player's Money Balance: "+ df.format(moneyBalance) +"\n";
return message;
}
public void makePlayer() {
boolean exit = false;
String message = "";
String propmt = "Type Here";
//generates a name for the player
name = new Name();
setName(name);
//generates a date of birth for the player
dob = new Date();
setDob(dob);
//adds money balance to the player
do {
//makes sure a valid number is entered
try {
message = "";
message = "Enter your money balance";
moneyBalance = Integer.parseInt(JOptionPane.showInputDialog(message, propmt));
exit = false;
}catch(java.lang.NumberFormatException e) {
message = "Please enter a valid number for money balance";
JOptionPane.showMessageDialog(null, message);
exit = true;
}
}while(exit == true);
//validates money balances to make sure it is > 0
setMoneyBalance(moneyBalance);
}
}// end Player