cgorrillaha

Untitled

Feb 24th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package Blackjack;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Player {
  6.     private ArrayList<Card> hand;
  7.  
  8.     public Player(){
  9.         hand=new ArrayList<>();
  10.     }
  11.  
  12.     public void addCardToHand(Card c){
  13.         hand.add(c);
  14.     }
  15.  
  16.     public int totalHand(){
  17.         int total=0;
  18.         int aceCount=0;
  19.  
  20.         for(Card c: hand){
  21.             total+=c.getRankValue();
  22.             if(c.getRank().equalsIgnoreCase("ace")){
  23.                 aceCount++;
  24.             }
  25.         }
  26.         while(aceCount>0&&total>21){
  27.             total-=10;
  28.             aceCount--;
  29.         }
  30.         return total;
  31.     }
  32.  
  33.     public int totalHand1(){
  34.         int total=0;
  35.         int aceCount=0;
  36.  
  37.         for(Card c: hand){
  38.             if(c.getRank().equalsIgnoreCase("ace")){
  39.                 total+=1;
  40.                 aceCount++;
  41.             }else {
  42.                 total += c.getRankValue();
  43.             }
  44.         }
  45.         if(aceCount>0&&total+10<=21){
  46.             total+=10;
  47.         }
  48.         return total;
  49.     }
  50.  
  51.     public void printHand(){
  52.         for(Card c: hand){
  53.             System.out.println(c.toString());
  54.         }
  55.     }
  56.  
  57. }
  58.  
Add Comment
Please, Sign In to add comment