Problem Statement

Modified Blackjack

  1. The game consists of a single player playing against the dealer, played by our program in this example.
  2. Each player is initially dealt two cards from a standard 52 card deck. Each card's value is its face value, with face cards having a value of 10, and aces are valued 11.
  3. The object of the game is to get a higher total value than the other player, without going over 21.
  4. The game consists of several steps:
    1. Both the player and the dealer review the two cards they are dealt. Both the player and the dealer can see the opponent's hand as well.
    2. The player is given the option to draw additional cards. The player may continue to draw cards until she or he chooses to stop, or their total value is greater than 21.
    3. If the player stops before going over 21, the dealer must draw cards to try and beat the player. The dealer stops drawing cards either when their total beats the player, or the dealer's total is greater than 21.
    4. At the end, the participant with the greatest card value that is less than or equal to 21 wins the game. If it is a tie, the dealer wins.

*~*sigh*~*

Image Credit: Giphy

Let's break it down into smaller parts



Use Classes!

Image Credit: Giphy

Let's break it down into classes




public class Card{
}


public class Card{
  //Attributes
  private String suit;
  private String name;
  private int value;
}

public class Card{
  //Attributes
  private String suit;
  private String name;
  private int value;
//Getters public String getSuit(){ return suit; } public String getName(){ return name; } public int getValue(){ return value; } }

public class Card{
  //Attributes & Getters ...
}


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){
} }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; this.name = a_number + ""; this.value = a_number; } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; this.name = a_number + ""; this.value = a_number; } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; if(){
}else{ this.name = a_number + ""; this.value = a_number; } } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; if(a_number == 1){
}else{ this.name = a_number + ""; this.value = a_number; } } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; if(a_number == 1){ this.name = "Ace"; this.value = 11; }else{ this.name = a_number + ""; this.value = a_number; } } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; if(a_number == 1){ this.name = "Ace"; this.value = 11; }else if (a_number == 11){ this.name = "Jack"; this.value = 10; }else if (a_number == 12){ this.name = "Queen"; this.value = 10; }else if (a_number == 13){ this.name = "King"; this.value = 10; }else{ this.name = a_number + ""; this.value = a_number; } } }


public class Card{
  //Attributes & Getters ...
public Card(String a_suit, int a_number){ this.suit = a_suit; if(a_number == 1){ this.name = "Ace"; this.value = 11; }else if (a_number == 11){ this.name = "Jack"; this.value = 10; }else if (a_number == 12){ this.name = "Queen"; this.value = 10; }else if (a_number == 13){ this.name = "King"; this.value = 10; }else{ this.name = a_number + ""; this.value = a_number; } } }


import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ if(!(a_suit.equals("Spades") || a_suit.equals("Hearts") || a_suit.equals("Clubs") || a_suit.equals("Diamonds"))){ throw new IllegalArgumentException("The suit must..."); } if(a_number < 1 || a_number > 13){ throw new IllegalArgumentException("The card..."); }
this.suit = a_suit; if(a_number == 1){ this.name = "Ace"; this.value = 11; }else if (a_number == 11){ this.name = "Jack"; this.value = 10; }else if (a_number == 12){ this.name = "Queen"; this.value = 10; }else if (a_number == 13){ this.name = "King"; this.value = 10; }else{ this.name = a_number + ""; this.value = a_number; } } }

import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ if(!(a_suit.equals("Spades") || a_suit.equals("Hearts") || a_suit.equals("Clubs") || a_suit.equals("Diamonds"))){ throw new IllegalArgumentException("The suit must..."); } if(a_number < 1 || a_number > 13){ throw new IllegalArgumentException("The card..."); }
this.suit = a_suit; if(a_number == 1){ this.name = "Ace"; this.value = 11; }else if (a_number == 11){ this.name = "Jack"; this.value = 10; }else if (a_number == 12){ this.name = "Queen"; this.value = 10; }else if (a_number == 13){ this.name = "King"; this.value = 10; }else{ this.name = a_number + ""; this.value = a_number; } } }


import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ ... } }


import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ ... } }



import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ ... }
public String toString(){ return this.name + " of " + this.suit; } }


import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ ... }
@Override public String toString(){ return this.name + " of " + this.suit; } }


import java.lang.IllegalArgumentException;
public class Card{ //Attributes & Getters ...
public Card(String a_suit, int a_number){ ... }
@Override public String toString(){ return this.name + " of " + this.suit; } }






public class Deck{

}



public class Deck{
private Card[] card_deck;
}



public class Deck{
private Card[] card_deck;
public Deck(){
}

}



public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; }
}


public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; for(String suit : suits){
}
}
}




public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; for(String suit : suits){ for(int i = 1; i <= 13; i++){ this.card_deck[??] = new Card(suit, i); } } }
}



public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; int card_number = 0; for(String suit : suits){ for(int i = 1; i <= 13; i++){ this.card_deck[card_number] = new Card(suit, i); card_number++; } } }
}



public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; int card_number = 0; for(String suit : suits){ for(int i = 1; i <= 13; i++){ this.card_deck[card_number] = new Card(suit, i); card_number++; } } }
}



public class Deck{
private Card[] card_deck;
public Deck(){ this.card_deck = new Card[52]; String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"}; int card_number = 0; for(String suit : suits){ for(int i = 1; i <= 13; i++){ this.card_deck[card_number] = new Card(suit, i); card_number++; } } }
@Override public String toString(){ String output = ""; for(Card a_card : this.card_deck){ output += a_card.toString() + "\n"; } return output; }
}


Let's Test It!




public class Main{
public static void main(String[] args){ Deck a_deck = new Deck(); System.out.println(a_deck.toString()); } }



public class Main{
public static void main(String[] args){ Deck a_deck = new Deck(); System.out.println(a_deck.toString()); } }



public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
}



public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){
}

}


public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){ for(int i = 0; i < times; i++){
}
}
}



import java.util.Random;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){ Random rando = new Random(); for(int i = 0; i < times; i++){ int first = rando.nextInt(52); int second = rando.nextInt(52); } }
}


import java.util.Random;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){ Random rando = new Random(); for(int i = 0; i < times; i++){ int first = rando.nextInt(52); int second = rando.nextInt(52); if(first != second){ Card temp = this.card_deck[first]; this.card_deck[first] = this.card_deck[second]; this.card_deck[second] = temp; } } }
}


import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){ if(times <= 0){ throw new IllegalArgumentException("The deck must ..."); } Random rando = new Random(); for(int i = 0; i < times; i++){ int first = rando.nextInt(52); int second = rando.nextInt(52); if(first != second){ Card temp = this.card_deck[first]; this.card_deck[first] = this.card_deck[second]; this.card_deck[second] = temp; } } }
}

import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...}
public void shuffle(int times){ if(times <= 0){ throw new IllegalArgumentException("The deck must ..."); } Random rando = new Random(); for(int i = 0; i < times; i++){ int first = rando.nextInt(52); int second = rando.nextInt(52); if(first != second){ Card temp = this.card_deck[first]; this.card_deck[first] = this.card_deck[second]; this.card_deck[second] = temp; } } }
}




Let's Test It!




public class Main{
public static void main(String[] args){ Deck a_deck = new Deck(); a_deck.shuffle(1000); System.out.println(a_deck.toString()); } }



public class Main{
public static void main(String[] args){ Deck a_deck = new Deck(); a_deck.shuffle(1000); System.out.println(a_deck.toString()); } }



import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...} public void shuffle(int times){...}
}


import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...} public void shuffle(int times){...}
public Card draw(){
}

}


import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck;
public Deck(){...} @Override public String toString(){...} public void shuffle(int times){...}
public Card draw(){ Card output = this.card_deck[this.card_position]; this.card_position++; return output; }
}


import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck; private int card_position;
public Deck(){ this.card_position = 0; ... }
@Override public String toString(){...} public void shuffle(int times){...}
public Card draw(){ Card output = this.card_deck[this.card_position]; this.card_position++; return output; }
}


import java.util.Random;
import java.lang.IllegalArgumentException;
public class Deck{
private Card[] card_deck; private int card_position;
public Deck(){ this.card_position = 0; ... }
@Override public String toString(){...} public void shuffle(int times){...}
public Card draw(){ Card output = this.card_deck[this.card_position]; this.card_position++; return output; }
}




public class Hand{
}


public class Hand{
private Card[] card_hand; private int hand_size;
public Hand(){ this.card_hand = new Card[52]; this.hand_size = 0; }
}


public class Hand{
private Card[] card_hand; private int hand_size;
public Hand(){ this.card_hand = new Card[52]; this.hand_size = 0; }
public int getValue(){ int value = 0; for(int i = 0; i < this.hand_size; i++){ value += this.card_hand[i].getValue(); } return value; }
@Override public String toString(){ String output = ""; for(int i = 0; i < this.hand_size; i++){ output += this.card_hand[i].toString() + "\n"; } return output; }
}


public class Hand{
private Card[] card_hand; private int hand_size;
public Hand(){ this.card_hand = new Card[52]; this.hand_size = 0; }
public int getValue(){ int value = 0; for(int i = 0; i < this.hand_size; i++){ value += this.card_hand[i].getValue(); } return value; }
@Override public String toString(){ String output = ""; for(int i = 0; i < this.hand_size; i++){ output += this.card_hand[i].toString() + "\n"; } return output; }
public void addCard(Card input){ this.card_hand[this.hand_size] = input; this.hand_size++; }
}




public class Dealer{
}


public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ this.my_hand = a_hand; }
}

public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ this.my_hand = a_hand; }
@Override public String toString(){ String output = "The dealer currently holds: \n"; output += this.my_hand.toString(); output += "for a total of " + this.my_hand.getValue(); return output; }
}

public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ ... } @Override public String toString(){ ... }
}


public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ ... } @Override public String toString(){ ... }
public void makeMoves(int player_value){
}
}


public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ ... } @Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ // we need to draw a card here! } }
}

public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ ... } @Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ // we need to draw a card here! } }
}

Option 1: Make Deck Static

Pros:

  • Requires few code changes
  • Can use deck from anywhere

Cons:

  • Can only have one deck
  • Not standard


Option 2: Pass Deck to Dealer

Pros:

  • No modification to deck
  • More object-oriented

Cons:

  • Have to manage deck instance
  • Easy to lose objects in code

public class Dealer{
private Hand my_hand;
public Dealer(Hand a_hand){ ... } @Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ // we need to draw a card here! } }
}

public class Dealer{
private Hand my_hand; private Deck the_deck;
public Dealer(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ // we need to draw a card here! } }
}


public class Dealer{
private Hand my_hand; private Deck the_deck;
public Dealer(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ Card new_card = this.the_deck.draw(); System.out.println("The dealer draws a " + new_card.toString()); this.my_hand.addCard(new_card); } }
}


public class Dealer{
private Hand my_hand; private Deck the_deck;
public Dealer(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ ... }
public void makeMoves(int player_value){ while(my_hand.getValue() < player_value && my_hand.getValue() <= 21){ Card new_card = this.the_deck.draw(); System.out.println("The dealer draws a " + new_card.toString()); this.my_hand.addCard(new_card); } }
}




public class Dealer{
private Hand my_hand; private Deck the_deck;
public Dealer(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ String output = "The dealer currently holds: \n"; output += this.my_hand.toString(); output += "for a total of " + this.my_hand.getValue(); return output; } }

public class Dealer{
private Hand my_hand; private Deck the_deck;
public Dealer(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ String output = "The dealer currently holds: \n"; output += this.my_hand.toString(); output += "for a total of " + this.my_hand.getValue(); return output; } }


public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ String output = "The player currently holds: \n"; output += this.my_hand.toString(); output += "for a total of " + this.my_hand.getValue(); return output; } }


public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ this.my_hand = a_hand; this.the_deck = a_deck; }
@Override public String toString(){ String output = "The player currently holds: \n"; output += this.my_hand.toString(); output += "for a total of " + this.my_hand.getValue(); return output; } }


public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }

}


public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){
}

}


import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){
}
}
}

import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){
}
} }
}


import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){ System.out.println("You currently have a value of " + this.my_hand.getValue()); System.out.print("Would you like to draw another card (y/n)?: "); String input = reader.nextLine().trim(); } } }
}


import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){ System.out.println("You currently have a value of " + this.my_hand.getValue()); System.out.print("Would you like to draw another card (y/n)?: "); String input = reader.nextLine().trim(); if(input.equals("y") || input.equals("Y")){ Card new_card = this.the_deck.draw(); System.out.println("You draw a " + new_card.toString()); this.my_hand.addCard(new_card); }else if (input.equals("n") || input.equals("N")){ break; }else{ System.out.println("Invalid input!"); } } } }
}



import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){ System.out.println("You currently have a value of " + this.my_hand.getValue()); System.out.print("Would you like to draw another card (y/n)?: "); String input = reader.nextLine().trim(); if(input.equals("y") || input.equals("Y")){ Card new_card = this.the_deck.draw(); System.out.println("You draw a " + new_card.toString()); this.my_hand.addCard(new_card); }else if (input.equals("n") || input.equals("N")){ break; }else{ System.out.println("Invalid input!"); } } System.out.println("You end your turn with a value of " + this.my_hand.getValue()); } }
}



import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){ System.out.println("You currently have a value of " + this.my_hand.getValue()); System.out.print("Would you like to draw another card (y/n)?: "); String input = reader.nextLine().trim(); if(input.equals("y") || input.equals("Y")){ Card new_card = this.the_deck.draw(); System.out.println("You draw a " + new_card.toString()); this.my_hand.addCard(new_card); }else if (input.equals("n") || input.equals("N")){ break; }else{ System.out.println("Invalid input!"); } } System.out.println("You end your turn with a value of " + this.my_hand.getValue()); }catch(Exception e){ System.out.println("An exception occurred!\n" + e); return; } }
}



import java.util.Scanner;
public class Player{
private Hand my_hand; private Deck the_deck;
public Player(Hand a_hand, Deck a_deck){ ... } @Override public String toString(){ ... }
public void makeMoves(){ try(Scanner reader = new Scanner(System.in)){ while(my_hand.getValue() <= 21){ System.out.println("You currently have a value of " + this.my_hand.getValue()); System.out.print("Would you like to draw another card (y/n)?: "); String input = reader.nextLine().trim(); if(input.equals("y") || input.equals("Y")){ Card new_card = this.the_deck.draw(); System.out.println("You draw a " + new_card.toString()); this.my_hand.addCard(new_card); }else if (input.equals("n") || input.equals("N")){ break; }else{ System.out.println("Invalid input!"); } } System.out.println("You end your turn with a value of " + this.my_hand.getValue()); }catch(Exception e){ System.out.println("An exception occurred!\n" + e); return; } }
}





public class Main{
public static void main(String[] args){
} }



public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); } }


public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); } }

public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); } }


public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); Hand dealer_hand = new Hand(); dealer_hand.addCard(the_deck.draw()); dealer_hand.addCard(the_deck.draw()); Dealer a_dealer = new Dealer(dealer_hand, the_deck); } }


public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); Hand dealer_hand = new Hand(); dealer_hand.addCard(the_deck.draw()); dealer_hand.addCard(the_deck.draw()); Dealer a_dealer = new Dealer(dealer_hand, the_deck); a_player.makeMoves(); } }

public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); Hand dealer_hand = new Hand(); dealer_hand.addCard(the_deck.draw()); dealer_hand.addCard(the_deck.draw()); Dealer a_dealer = new Dealer(dealer_hand, the_deck); a_player.makeMoves(); a_dealer.makeMoves(player_hand.getValue()); } }

public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); Hand dealer_hand = new Hand(); dealer_hand.addCard(the_deck.draw()); dealer_hand.addCard(the_deck.draw()); Dealer a_dealer = new Dealer(dealer_hand, the_deck); a_player.makeMoves(); a_dealer.makeMoves(player_hand.getValue());
if(player_hand.getValue() <= 21 && dealer_hand.getValue() > 21){ System.out.println("The player wins!"); }else if(player_hand.getValue() <= 21 && player_hand.getValue() > dealer_hand.getValue()){ System.out.println("The player wins!"); }else if(dealer_hand.getValue() <= 21){ System.out.println("The dealer wins!"); }else{ System.out.println("There is no winner"); } } }

public class Main{
public static void main(String[] args){ Deck the_deck = new Deck(); the_deck.shuffle(1000); Hand player_hand = new Hand(); player_hand.addCard(the_deck.draw()); player_hand.addCard(the_deck.draw()); Player a_player = new Player(player_hand, the_deck); Hand dealer_hand = new Hand(); dealer_hand.addCard(the_deck.draw()); dealer_hand.addCard(the_deck.draw()); Dealer a_dealer = new Dealer(dealer_hand, the_deck); a_player.makeMoves(); a_dealer.makeMoves(player_hand.getValue());
if(player_hand.getValue() <= 21 && dealer_hand.getValue() > 21){ System.out.println("The player wins!"); }else if(player_hand.getValue() <= 21 && player_hand.getValue() > dealer_hand.getValue()){ System.out.println("The player wins!"); }else if(dealer_hand.getValue() <= 21){ System.out.println("The dealer wins!"); }else{ System.out.println("There is no winner"); } } }