Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Blackjack;
- import java.util.ArrayList;
- public class Player {
- private ArrayList<Card> hand;
- public Player(){
- hand=new ArrayList<>();
- }
- public void addCardToHand(Card c){
- hand.add(c);
- }
- public int totalHand(){
- int total=0;
- int aceCount=0;
- for(Card c: hand){
- total+=c.getRankValue();
- if(c.getRank().equalsIgnoreCase("ace")){
- aceCount++;
- }
- }
- while(aceCount>0&&total>21){
- total-=10;
- aceCount--;
- }
- return total;
- }
- public int totalHand1(){
- int total=0;
- int aceCount=0;
- for(Card c: hand){
- if(c.getRank().equalsIgnoreCase("ace")){
- total+=1;
- aceCount++;
- }else {
- total += c.getRankValue();
- }
- }
- if(aceCount>0&&total+10<=21){
- total+=10;
- }
- return total;
- }
- public void printHand(){
- for(Card c: hand){
- System.out.println(c.toString());
- }
- }
- }
Add Comment
Please, Sign In to add comment