use java language Create a class for casino chips. When a Chip object is created
ID: 3566364 • Letter: U
Question
use java language
Create a class for casino chips. When a Chip object is created, it should have a
String to store it's colour and an int to store the colour value. Create a Dealer class with the
following methods
public void CollectChips(int num, Chip colour)
public void PayoutChips(int num, Chip colour)
public int CountMoney()
Write a tester program that creates a Dealer object and three different coloured chip objects.
Simulate a round of blackjack where multiple players lose various amounts and colours of chips,
and other players win some chips. Use the method CountMoney and display the remaining
money in the dealer's tray. You may assume that the dealer can convert any number of one
coloured chip in to another colour as long as the value remains the same.
Explanation / Answer
import java.util.Scanner; import static java.lang.System.out; class CasinoChips { 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 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 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(); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.