"import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class HighSum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(“HighSum GAME”);
System.out.println(“================================================================================”);

// Login system
String username = “”;
while (true) {
System.out.print(“Enter your username: “);
username = input.nextLine();

System.out.print(“Enter your password: “);
String password = input.nextLine();

if (password.equals(“password”)) {
System.out.println();
System.out.println(“HighSum GAME”);
System.out.println(”================================================================================”);

System.out.println(username + “, You have 100 chips”);
break;
} else {
System.out.println(“Incorrect username or password. Please try again.”);
}
}

// Set initial chips to 100
int chips = 100;

boolean keepPlaying = true;
while (keepPlaying) {
System.out.println(”--------------------------------------------------------------------------------”);
System.out.println(“Game starts - Dealer shuffles deck.”);
System.out.println(“--------------------------------------------------------------------------------”);

chips = playRound(username, chips, input);

System.out.println(“--------------------------------------------------------------------------------”);
System.out.print(“Next Game? (Y/N) > “);
String nextGame = input.next();
keepPlaying = nextGame.equalsIgnoreCase(“Y”);

if (keepPlaying) {
chips = 100;
}
}

input.close();
}

static int playRound(String username, int chips, Scanner input) {
int roundNumber = 1;
int currentBet = 0;
boolean quit = false;

// Create and shuffle deck
ArrayList<Card> deck = new ArrayList<Card>();
String[] suits = {“Hearts”, “Diamonds”, “Clubs”, “Spades”};
String[] ranks = {“Ace”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “Jack”, “Queen”, “King”};
for (String suit : suits) {
for (String rank : ranks) {
deck.add(new Card(suit, rank));
}
}
Collections.shuffle(deck);

// Deal cards to players
ArrayList<Card> playerHand = new ArrayList<Card>();
ArrayList<Card> dealerHand = new ArrayList<Card>();

while (roundNumber <= 4 && !quit) {
System.out.println(“Dealer dealing cards - ROUND " + roundNumber);
System.out.println(”--------------------------------------------------------------------------------”);

// Add cards
playerHand.add(deck.remove(0));
dealerHand.add(deck.remove(0));

// Print players’ hands
System.out.println(“Dealer”);
if (roundNumber == 1) {
System.out.print(”<HIDDEN CARD> “);
} else {
System.out.print(”<" + dealerHand.get(0) + “> “);
}
for (int i = 1; i < dealerHand.size(); i++) {
System.out.print(”<” + dealerHand.get(i) + “> “);
}
System.out.println();

System.out.println(username);
for (Card card : playerHand) {
System.out.print(”<” + card + "> ");
}
System.out.println();
System.out.println("Value: " + playerHand.stream().mapToInt(Card::getValue).sum());

// Bet
boolean playerHasHigherCard = playerHand.get(playerHand.size() - 1).getValue() > dealerHand.get(dealerHand.size() - 1).getValue();
if ((roundNumber == 1 && playerHasHigherCard) || roundNumber > 1) {
if (roundNumber == 1) {
System.out.print("Do you want to follow? [Y/N]: ");
String follow = input.next();
if (follow.equalsIgnoreCase(“Y”)) {
System.out.print("Player call, state bet: ");
currentBet = input.nextInt();
if (currentBet > 10) {
System.out.println(“Maximum Bet is 10 chips”);
currentBet = 10;
}
} else {
quit = true;
}
} else {
System.out.print(“Do you want to [C]all or [Q]uit?: “);
String callOrQuit = input.next();
if (callOrQuit.equalsIgnoreCase(“Q”)) {
quit = true;
}
}
} else if (roundNumber == 1) {
System.out.print(“Dealer call, state bet: “);
currentBet = (int) (Math.random() * (chips / 2) + 1);
if (currentBet > 10) {
currentBet = 10;
}
System.out.println(currentBet);
}

if (quit) {
chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2));
System.out.println(“Dealer Wins”);
return chips;
}

chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2 * roundNumber));
System.out.println(”--------------------------------------------------------------------------------”);
roundNumber++;
}

if (!quit) {
System.out.println(“Game End - Dealer reveal hidden cards”);
System.out.println(”--------------------------------------------------------------------------------”);

// Reveal dealer’s hand
System.out.println(“Dealer”);
for (Card card : dealerHand) {
System.out.print(”<” + card + “> “);
}
System.out.println();
System.out.println(“Value : " + dealerHand.stream().mapToInt(Card::getValue).sum());

// Compare player and dealer values
int playerValue = playerHand.stream().mapToInt(Card::getValue).sum();
int dealerValue = dealerHand.stream().mapToInt(Card::getValue).sum();

if (playerValue > dealerValue) {
System.out.println(username + " Wins”);
chips += (currentBet * 2 * (roundNumber - 1));
} else {
System.out.println(“Dealer Wins”);
}

System.out.println(username + “, You have " + chips + " chips”);
System.out.println(“Dealer shuffles used cards and place behind the deck.”);
System.out.println(”--------------------------------------------------------------------------------”);
}

return chips;
}
}

class Card {
private String suit;
private String rank;

public Card(String suit, String rank) {
this.suit = suit;
this.rank = rank;
}

public String getSuit() {
return suit;
}

public String getRank() {
return rank;
}

public int getValue() {
if (rank.equals(“Ace”)) {
return 14;
} else if (rank.equals(“King”)) {
return 13;
} else if (rank.equals(“Queen”)) {
return 12;
} else if (rank.equals(“Jack”)) {
return 11;
} else {
return Integer.parseInt(rank);
}
}

public String toString() {
return rank + " of " + suit;
}
}
for round 1 “Do you want to follow? [Y/N]:” is not needed. Display current amount bet by player or dealer depending whose most recent card is bigger by displaying “Dealer/Player call, state bet:”. Ask for betting input after player calls if the player’s most recent card is bigger than the dealer. Remove max bet. Chips bet cannot be negative. If chips are insufficient, notify the player and display message “Chips insufficient” and let the player enter bet again.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class HighSum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(“HighSum GAME”);
System.out.println(“================================================================================”);

// Login system
String username = “”;
while (true) {
System.out.print(“Enter your username: “);
username = input.nextLine();

System.out.print(“Enter your password: “);
String password = input.nextLine();

if (password.equals(“password”)) {
System.out.println();
System.out.println(“HighSum GAME”);
System.out.println(”================================================================================”);

System.out.println(username + “, You have 100 chips”);
break;
} else {
System.out.println(“Incorrect username or password. Please try again.”);
}
}

// Set initial chips to 100
int chips = 100;

boolean keepPlaying = true;
while (keepPlaying) {
System.out.println(”--------------------------------------------------------------------------------”);
System.out.println(“Game starts - Dealer shuffles deck.”);
System.out.println(“--------------------------------------------------------------------------------”);

chips = playRound(username, chips, input);

System.out.println(“--------------------------------------------------------------------------------”);
System.out.print(“Next Game? (Y/N) > “);
String nextGame = input.next();
keepPlaying = nextGame.equalsIgnoreCase(“Y”);

if (keepPlaying) {
chips = 100;
}
}

input.close();
}

static int playRound(String username, int chips, Scanner input) {
int roundNumber = 1;
int currentBet = 0;
boolean quit = false;

// Create and shuffle deck
ArrayList<Card> deck = new ArrayList<Card>();
String[] suits = {“Hearts”, “Diamonds”, “Clubs”, “Spades”};
String[] ranks = {“Ace”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “Jack”, “Queen”, “King”};
for (String suit : suits) {
for (String rank : ranks) {
deck.add(new Card(suit, rank));
}
}
Collections.shuffle(deck);

// Deal cards to players
ArrayList<Card> playerHand = new ArrayList<Card>();
ArrayList<Card> dealerHand = new ArrayList<Card>();

while (roundNumber <= 4 && !quit) {
System.out.println(“Dealer dealing cards - ROUND " + roundNumber);
System.out.println(”--------------------------------------------------------------------------------”);

// Add cards
playerHand.add(deck.remove(0));
dealerHand.add(deck.remove(0));

// Print players’ hands
System.out.println(“Dealer”);
if (roundNumber == 1) {
System.out.print(”<HIDDEN CARD> “);
} else {
System.out.print(”<" + dealerHand.get(0) + “> “);
}
for (int i = 1; i < dealerHand.size(); i++) {
System.out.print(”<” + dealerHand.get(i) + “> “);
}
System.out.println();

System.out.println(username);
for (Card card : playerHand) {
System.out.print(”<” + card + "> ");
}
System.out.println();
System.out.println("Value: " + playerHand.stream().mapToInt(Card::getValue).sum());

// Bet
boolean playerHasHigherCard = playerHand.get(playerHand.size() - 1).getValue() > dealerHand.get(dealerHand.size() - 1).getValue();
if (roundNumber == 1) {
if (playerHasHigherCard) {
System.out.print("Player call, state bet: ");
while (true) {
currentBet = input.nextInt();
if (currentBet > chips) {
System.out.println(“Chips insufficient”);
System.out.print("Player call, state bet: ");
} else if (currentBet < 0) {
System.out.println(“Chips cannot be negative”);
System.out.print("Player call, state bet: ");
} else {
break;
}
}
} else {
System.out.print(“Dealer call, state bet: “);
currentBet = (int) (Math.random() * (chips / 2) + 1);
System.out.println(currentBet);
}
} else {
System.out.print(“Do you want to [C]all or [Q]uit?: “);
String callOrQuit = input.next();
if (callOrQuit.equalsIgnoreCase(“Q”)) {
quit = true;
}
}

if (quit) {
chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2));
System.out.println(“Dealer Wins”);
return chips;
}

chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2 * roundNumber));
System.out.println(”--------------------------------------------------------------------------------”);
roundNumber++;
}

if (!quit) {
System.out.println(“Game End - Dealer reveal hidden cards”);
System.out.println(”--------------------------------------------------------------------------------”);

// Reveal dealer’s hand
System.out.println(“Dealer”);
for (Card card : dealerHand) {
System.out.print(”<” + card + “> “);
}
System.out.println();
System.out.println(“Value : " + dealerHand.stream().mapToInt(Card::getValue).sum());

// Compare player and dealer values
int playerValue = playerHand.stream().mapToInt(Card::getValue).sum();
int dealerValue = dealerHand.stream().mapToInt(Card::getValue).sum();

if (playerValue > dealerValue) {
System.out.println(username + " Wins”);
chips += (currentBet * 2 * (roundNumber - 1));
} else {
System.out.println(“Dealer Wins”);
}

System.out.println(username + “, You have " + chips + " chips”);
System.out.println(“Dealer shuffles used cards and place behind the deck.”);
System.out.println(”--------------------------------------------------------------------------------”);
}

return chips;
}
}

class Card {
private String suit;
private String rank;

public Card(String suit, String rank) {
this.suit = suit;
this.rank = rank;
}

public String getSuit() {
return suit;
}

public String getRank() {
return rank;
}

public int getValue() {
if (rank.equals(“Ace”)) {
return 14;
} else if (rank.equals(“King”)) {
return 13;
} else if (rank.equals(“Queen”)) {
return 12;
} else if (rank.equals(“Jack”)) {
return 11;
} else {
return Integer.parseInt(rank);
}
}

public String toString() {
return rank + " of " + suit;
}
}
add state bet to each round and allow player to bet after calling if their card is bigger than dealer’s. Round 1 starts with 2 cards, only 1 of the dealer’s card is Hidden, player’s card is shown as normal.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class HighSum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(“HighSum GAME”);
System.out.println(“================================================================================”);

// Login system
String username = “”;
while (true) {
System.out.print(“Enter your username: “);
username = input.nextLine();

System.out.print(“Enter your password: “);
String password = input.nextLine();

if (password.equals(“password”)) {
System.out.println();
System.out.println(“HighSum GAME”);
System.out.println(”================================================================================”);

System.out.println(username + “, You have 100 chips”);
break;
} else {
System.out.println(“Incorrect username or password. Please try again.”);
}
}

// Set initial chips to 100
int chips = 100;

boolean keepPlaying = true;
while (keepPlaying) {
System.out.println(”--------------------------------------------------------------------------------”);
System.out.println(“Game starts - Dealer shuffles deck.”);
System.out.println(“--------------------------------------------------------------------------------”);

chips = playRound(username, chips, input);

System.out.println(“--------------------------------------------------------------------------------”);
System.out.print(“Next Game? (Y/N) > “);
String nextGame = input.next();
keepPlaying = nextGame.equalsIgnoreCase(“Y”);

if (keepPlaying) {
chips = 100;
}
}

input.close();
}

static int playRound(String username, int chips, Scanner input) {
int roundNumber = 1;
int currentBet = 0;
boolean quit = false;

// Create and shuffle deck
ArrayList<Card> deck = new ArrayList<Card>();
String[] suits = {“Hearts”, “Diamonds”, “Clubs”, “Spades”};
String[] ranks = {“Ace”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “Jack”, “Queen”, “King”};
for (String suit : suits) {
for (String rank : ranks) {
deck.add(new Card(suit, rank));
}
}
Collections.shuffle(deck);

// Deal cards to players
ArrayList<Card> playerHand = new ArrayList<Card>();
ArrayList<Card> dealerHand = new ArrayList<Card>();

// Initial deal: 2 cards for each player
playerHand.add(deck.remove(0));
dealerHand.add(deck.remove(0));
playerHand.add(deck.remove(0));
dealerHand.add(deck.remove(0));

while (roundNumber <= 4 && !quit) {
System.out.println(“Dealer dealing cards - ROUND " + roundNumber);
System.out.println(”--------------------------------------------------------------------------------”);

if (roundNumber > 1) {
// Add cards
playerHand.add(deck.remove(0));
dealerHand.add(deck.remove(0));
}

// Print players’ hands
System.out.println(“Dealer”);
if (roundNumber == 1) {
System.out.print(”<HIDDEN CARD> “);
System.out.print(”<" + dealerHand.get(1) + “> “);
} else {
for (Card card : dealerHand) {
System.out.print(”<” + card + “> “);
}
}
System.out.println();

System.out.println(username);
for (Card card : playerHand) {
System.out.print(”<” + card + "> ");
}
System.out.println();
System.out.println("Value: " + playerHand.stream().mapToInt(Card::getValue).sum());

// Bet
boolean playerHasHigherCard = playerHand.get(playerHand.size() - 1).getValue() > dealerHand.get(dealerHand.size() - 1).getValue();
if (playerHasHigherCard) {
System.out.print("Player call, state bet: ");
while (true) {
currentBet = input.nextInt();
if (currentBet > chips) {
System.out.println(“Chips insufficient”);
System.out.print("Player call, state bet: ");
} else if (currentBet < 0) {
System.out.println(“Chips cannot be negative”);
System.out.print("Player call, state bet: ");
} else {
break;
}
}
} else {
System.out.print(“Dealer call, state bet: “);
currentBet = (int) (Math.random() * (chips / 2) + 1);
System.out.println(currentBet);
}

System.out.print(“Do you want to [C]all or [Q]uit?: “);
String callOrQuit = input.next();
if (callOrQuit.equalsIgnoreCase(“Q”)) {
quit = true;
}

if (quit) {
chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2));
System.out.println(“Dealer Wins”);
return chips;
}

chips -= currentBet;
System.out.println(username + “, You are left with " + chips + " chips”);
System.out.println(“Bet on table : " + (currentBet * 2 * roundNumber));
System.out.println(”--------------------------------------------------------------------------------”);
roundNumber++;
}

if (!quit) {
System.out.println(“Game End - Dealer reveal hidden cards”);
System.out.println(”--------------------------------------------------------------------------------”);

// Reveal dealer’s hand
System.out.println(“Dealer”);
for (Card card : dealerHand) {
System.out.print(”<” + card + “> “);
}
System.out.println();
System.out.println(“Value : " + dealerHand.stream().mapToInt(Card::getValue).sum());

// Compare player and dealer values
int playerValue = playerHand.stream().mapToInt(Card::getValue).sum();
int dealerValue = dealerHand.stream().mapToInt(Card::getValue).sum();

if (playerValue > dealerValue) {
System.out.println(username + " Wins”);
chips += (currentBet * 2 * (roundNumber - 1));
} else {
System.out.println(“Dealer Wins”);
}

System.out.println(username + “, You have " + chips + " chips”);
System.out.println(“Dealer shuffles used cards and place behind the deck.”);
System.out.println(”--------------------------------------------------------------------------------”);
}

return chips;
}
}

class Card {
private String suit;
private String rank;

public Card(String suit, String rank) {
this.suit = suit;
this.rank = rank;
}

public String getSuit() {
return suit;
}

public String getRank() {
return rank;
}

public int getValue() {
if (rank.equals(“Ace”)) {
return 14;
} else if (rank.equals(“King”)) {
return 13;
} else if (rank.equals(“Queen”)) {
return 12;
} else if (rank.equals(“Jack”)) {
return 11;
} else {
return Integer.parseInt(rank);
}
}

public String toString() {
return rank + " of " + suit;
}
}"

Ask player to call or quit before asking state bet. Dealer same as player in the whole game cannot spend past 100 chips in bets. Dealer's hidden card is hidden during the game and is only revealed after round 4 when the game ends.