-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
74 lines (72 loc) · 1.81 KB
/
Copy pathPlayer.java
File metadata and controls
74 lines (72 loc) · 1.81 KB
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
import java.util.Scanner;
import java.util.ArrayList;
public class Player
{
Scanner scan = new Scanner(System.in);
//player hand
ArrayList<Card> hand = new ArrayList<Card>();
private String name;
private int totalValue = 0;
private double money;
private boolean choiceStay = false;
public Player(String nm, double mon)
{
// initialise instance variables
name = nm;
money = mon;
}
//places bet based on user input
public double bet(){
//holds money to be bet
System.out.println("How much would you like to bet");
double holder = scan.nextInt();
money -= holder;
return holder;
}
//hits
public void hit(Card newCard){
addCard(newCard);
}
//adds a new card and updates value
public void addCard(Card newCard){
hand.add(newCard);
totalValue = handTotal();
}
// //sums up all card values and returns it
public int handTotal(){
int sum = 0;
for(int i=0;i<hand.size();i++){
sum += hand.get(i).getValue();
}
if(sum>21){
for(int i=0;i<hand.size();i++){
if(hand.get(i).getValue()==11){
hand.get(i).setValue(1);
}
}
}
return sum;
}
//gives hand total
public String toString(){
return "The hand total is " + totalValue;
}
public void stay(){
choiceStay = true;
}
public boolean getChoiceStay(){
return choiceStay;
}
//changes amt of money
public void setMoney(double mn){
money+=mn;
}
//returns amt of money
public double getMoney(){
return money;
}
//returns total value
public int getTotalValue(){
return totalValue;
}
}