Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:58:42+00:00 2026-06-13T12:58:42+00:00

I am trying to write a program which can keep track of the number

  • 0

I am trying to write a program which can keep track of the number of chips each player has in poker. This is not a poker game, only a program which can keep the number of chips each player has. However, I want to be able to “bet” “call” “fold” etc and be able to automatically keep track.

My question is, is there a way for adjusting the number of players without writing each permutations? Currently, it can only keep track of 2 people. How would I make it so it can theoretically keep track of an infinite amount of people? I’ve written every permutation possible and I know it’s not very efficient so is there a more efficient way of coding this?

I am a java noob so any help would be appreciated.

import java.util.Scanner;
import static java.lang.System.out;

class Chips {
static String move; //first move
static int betVal1, betVal2;
static int pot;
static int P1, P2;
static int roundcount;
static String player;
static Scanner myScanner = new Scanner(System.in);
static int turncount;
static String outcome;

public static void firstP1() { //first move when P1 start
    out.print("P1 - will you 'Bet', 'Check' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
    out.print("Please type 'Bet', 'Check' or 'Fold'");
    move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? If you've changed your mind: Type '0' to check and '-1' to fold. ");
        betVal1 = myScanner.nextInt();

        while (betVal1 > P1) {
            out.print("You cannot bet more than your chip count. How much will you bet? ");
            betVal1 = myScanner.nextInt();
        }
        if (betVal1 == 0) { //check
            P2aftercheck();
        }
        if (betVal1 == -1) { //fold
            P2 += pot;
            pot = 0;
            roundcount = 0;
            turncount++;

            out.print("P1: ");
            out.println(P1);
            out.print("P2: ");
            out.println(P2);
            out.println("Next turn");

            if (turncount  % 2 == 0) { //check to see who begins next turn
                player = "One";
            } else {
                player = "Two";         
            }

            if( player.equals("One")) {
                firstP1();
            } else {
                firstP2();
            }

        }


        pot += betVal1;
        P1 -= betVal1;
        //out.println(betVal);
        //out.print(pot);
        P2afterbet();
        break;

    case "Check":
        P2aftercheck();
        break;

    case "Fold":
        P2 += pot;
        pot = 0;
        roundcount = 0;
        turncount++;

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    }
}

public static void firstP2() { //first move when P2 start
    out.print("P2 - will you 'Bet', 'Check' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
    out.print("Please type 'Bet', 'Check' or 'Fold' ");
    move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? ");
        betVal2 = myScanner.nextInt();
        while (betVal2 > P2) {
            out.print("You can not bet more than your chip count. How much will you bet? ");
            betVal2 = myScanner.nextInt();
        }
        pot += betVal2;
        P2 -= betVal2;
        //out.println(betVal);
        //out.print(pot);
        P1afterbet();
        break;

    case "Check":
        P1aftercheck();
        break;

    case "Fold":
        P1 += pot;
        pot = 0;
        roundcount = 0;
        turncount++;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    }
}

public static void P1afterbet() { //P1 move after P2 bet
    out.print("P1 - will you 'Bet', 'Call' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Call") && !move.equals("Fold")){
        out.print("Please type 'Bet', 'Check' or 'Fold' ");
        move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? ");
        betVal1 = myScanner.nextInt();
        while (betVal1 < betVal2){
            out.print("Please bet at least ");
            out.print(betVal2);
            out.println(" chips.");
            out.print("How much will you bet? ");
            betVal1 = myScanner.nextInt();
        }

        pot += betVal1;
        P1 -= betVal1;
        P2afterbet();
        break;

    case "Call":
        pot += betVal1;
        P1 -= betVal1;
        roundcount++;
        if (roundcount == 4){
            roundend();
        }
        if( player.equals("P1")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    case "Fold":
        P2 += pot;
        pot = 0;
        roundcount = 0;
        turncount++;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;
    }
}

public static void P1aftercheck() { //P1 move after P2 check
    out.print("P1 - will you 'Bet', 'Check' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
    out.print("Please type 'Bet', 'Check' or 'Fold'");
    move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? ");
        betVal1 = myScanner.nextInt();
        while (betVal1 > P1) {
            out.print("You can not bet more than your chip count. How much will you bet? ");
            betVal1 = myScanner.nextInt();
        }
        pot += betVal1;
        P1 -= betVal1;
        //out.println(betVal);
        //out.print(pot);
        P2afterbet();
        break;

    case "Check":
        roundcount++;
        if (roundcount == 4) {
            roundend();
        }
        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    case "Fold":
        P2 += pot;
        pot = 0;
        roundcount=0;
        turncount++; 

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    }
}

public static void P2afterbet() { //P2 move after P1 bet
    out.print("P2 - will you 'Bet', 'Call' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Call") && !move.equals("Fold")){
    out.print("Please type 'Bet', 'Check' or 'Fold'");
    move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? ");
        betVal2 = myScanner.nextInt();
        while (betVal2 > P2) {
            out.print("You can not bet more than your chip count. How much will you bet? ");
            betVal2 = myScanner.nextInt();
        }
        while (betVal2 < betVal1) {
            out.print("You must bet at least ");
            out.print(betVal1);
            betVal2 = myScanner.nextInt();
        }
        pot += betVal2;
        P2 -= betVal2;
        //out.println(betVal);
        //out.print(pot);
        P1afterbet();
        break;

    case "Call":
        P2 -= betVal1;
        pot += betVal1;
        roundcount++;
        if (roundcount == 4){
            roundend();
        }
        if( player.equals("P1")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    case "Fold":
        P1 += pot;
        pot = 0;
        roundcount = 0;
        turncount++;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }
        break;

    }
}

public static void P2aftercheck() { //P2 move after P1 check
    out.print("P2 - will you 'Bet', 'Check' or 'Fold'? ");
    move = myScanner.next();

    while (!move.equals("Bet") && !move.equals("Check") && !move.equals("Fold")){
    out.print("Please type 'Bet', 'Check' or 'Fold'");
    move = myScanner.next();
    }

    switch(move) {
    case "Bet":
        out.print("How much will you bet? ");
        betVal2 = myScanner.nextInt();
        while (betVal2 > P1) {
            out.print("You can not bet more than your chip count. How much will you bet? ");
            betVal2 = myScanner.nextInt();
        }
        pot += betVal2;
        P2 -= betVal2;
        //out.println(betVal);
        //out.print(pot);
        P1afterbet();
        break;

    case "Check":
        roundcount++;
        if (roundcount == 4){
            roundend();
        }
        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }

        break;

    case "Fold":
        P1 += pot;
        pot = 0;
        roundcount=0;
        turncount++;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (turncount  % 2 == 0) {
            player = "One";
        } else {
            player = "Two";         
        }

        if( player.equals("One")) {
            firstP1();
        } else {
            firstP2();
        }

        break;

    }
}

public static void roundend() {
    out.print("Who won the round? 'P1' or 'P2'? ");
    outcome = myScanner.next();
    turncount++;

    if (turncount  % 2 == 0) {
        player = "One";
    } else {
        player = "Two";         
    }

    while (!outcome.equals("P1") && !outcome.equals("P2")){
        out.print("Please type 'P1' or 'P2'");
        outcome = myScanner.next();
    }

    if (outcome.equals("P1")){
        P1 += pot;
        pot = 0;
        roundcount = 0;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (P1 != 0 && P2 != 0){
            if( player.equals("One")) {
                firstP1();
            } else {
                firstP2();
            }
        } else if (P1 == 0) {
            out.print("P1 is out of chips. P2 Wins!");
        } else {
            out.print("P2 is out of chips. P2 Wins!");
        }
    } else {
        P2 += pot;
        pot = 0;
        roundcount = 0;

        out.print("P1: ");
        out.println(P1);
        out.print("P2: ");
        out.println(P2);
        out.println("Next turn");

        if (P1 != 0 && P2 != 0) {
            if( player.equals("P1")) {
                firstP1();
            } else {
                firstP2();
            }
        } else if (P1 == 0) {
            out.print("P1 is out of chips. P2 Wins!");
        } else {
            out.print("P2 is out of chips. P2 Wins!");
        }
    } 

    System.exit(0);
}

public static void main(String args[]){

    pot = 0;
    roundcount = 0; //status within turn i.e. Flop, Turn, River
    turncount = 2; //use for who starts

    out.print("Please enter starting chip count ");
    P1 = myScanner.nextInt();
    P2 = P1;

    firstP1();
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:58:43+00:00Added an answer on June 13, 2026 at 12:58 pm

    Yes but you will need to re-think the way your program is designed.

    The easiest way to do this would be to create a Player class, and implement every action a player performs as a method within this class. In order to manage the Player’s chips you would have a variable Player.chips that is either globally accessible or managed with methods such as Player.getChips() and Player.setChips().

    For multiple players you would have an array of Player‘s ie.

    Player[] Players; 
    Players[0] = new Player();
    Players[1] = new Player();
    

    The following post may help you more (similar problem but using Blackjack instead of Poker ) – How to initialize an array of objects in Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a server program which can keep a track of the
I am trying to write a program in java which can count number of
I've been trying to write a program in java that can download a number
Perhaps I'm being over-ambitious, but I'm trying to write a server program which can
I am trying to write a program which can calculate factorial from 1-9 by
I am trying to write a program which gets input files and prints included
I am trying to write a program in PHP which I had already written
I'm trying to write a program in C++ which runs Conway's Game of Life.
I am trying to write a simple java program which returns me all the
I'm trying to write a program in Control Language which creates and populates a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.