Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java... my code gets error.. Exception in thread main java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at GameFile.load(GameFile.java:20) at

Java... my code gets error..

Exception in thread "main" java.util.InputMismatchException

at java.util.Scanner.throwFor(Unknown Source)

at java.util.Scanner.next(Unknown Source)

at java.util.Scanner.nextInt(Unknown Source)

at java.util.Scanner.nextInt(Unknown Source)

at GameFile.load(GameFile.java:20)

at Roulette.main(Roulette.java:10)

games.txt

100A 2 1 20 50 100 200 1000 5 100 100 200 500 1000

players

0 100 1 500 1234 Jane Smith 1 300 3455 John Smith 0 500 2 1000 9867 Hot Shot 0 200 0 300 2 2000 5555 Charles B

Roulette.java

-----------------------------------------------------------------

import java.util.ArrayList;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

public class Roulette {

public static void main(String[] args)throws IOException{

ArrayList currentGames = new ArrayList();

ArrayList currentPlayers = new ArrayList();

GameFile.load(currentGames, currentPlayers);

System.out.println(currentGames);

System.out.println(currentPlayers);

JFrame frame = new JFrame("Roulette");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(new GameWindow(currentGames, currentPlayers));

frame.pack();

frame.setVisible(true);

}

public static class GameWindow extends JPanel{

JLabel mainMenu;

JLabel mainOptions;

JButton selectAGame, addAPlayer,quit;

JButton playerButton,vipPlayerButton;

JButton addRegularButton, addVipButton;

JTextField moneyField, idField, nameField;

JPanel menuPanel, addAPlayerPanel, addRegularPlayer, addVipPlayer;

ArrayList availableGames;

ArrayList availablePlayers;

public GameWindow(ArrayList availableGames, ArrayList availablePlayers){

this.availableGames = availableGames;

this.availablePlayers = availablePlayers;

setBackground(Color.yellow);

mainMenu = new JLabel("Main Menu",JLabel.CENTER);

selectAGame = new JButton("Select A Game");

addAPlayer = new JButton("Add A Player");

addAPlayer.addActionListener(new ButtonListener());

quit = new JButton("Quit");

menuPanel =new JPanel(new FlowLayout());

menuPanel.setPreferredSize(new Dimension(170, 265));

menuPanel.setBackground(Color.yellow);

menuPanel.add(mainMenu);

menuPanel.add(selectAGame);

menuPanel.add(addAPlayer);

menuPanel.add(quit);

add(menuPanel);

setBackground(Color.yellow);

setPreferredSize(new Dimension(450,550));

}

public JPanel addAPlayerPanel(){

addAPlayerPanel = new JPanel();

addAPlayerPanel.setLayout(new FlowLayout());

addAPlayerPanel.setPreferredSize(new Dimension(170, 265));

addAPlayerPanel.setBackground(Color.yellow);

JLabel heading = new JLabel("Adding a player", JLabel.CENTER);

playerButton = new JButton("Add a regular player");

playerButton.addActionListener(new ButtonListener());

vipPlayerButton = new JButton("Add a vip player");

vipPlayerButton.addActionListener(new ButtonListener());

addAPlayerPanel.add(heading);

addAPlayerPanel.add(playerButton);

addAPlayerPanel.add(vipPlayerButton);

return addAPlayerPanel;

}

public void addRegularPlayer(){

addRegularPlayer = new JPanel();

addRegularPlayer.setLayout(new FlowLayout());

addRegularPlayer.setPreferredSize(new Dimension(200, 265));

addRegularPlayer.setBackground(Color.yellow);

JLabel heading = new JLabel("Adding a regular player", JLabel.CENTER);

addRegularButton = new JButton("Add");

addRegularButton.addActionListener(new addButtonListener());

JLabel money = new JLabel("Money the player's have:");

moneyField = new JTextField(5);

addRegularPlayer.add(heading);

addRegularPlayer.add(money);

addRegularPlayer.add(moneyField);

addRegularPlayer.add(addRegularButton);

add(addRegularPlayer);

updateUI();

}

public void addVipPlayer(){

addVipPlayer = new JPanel();

addVipPlayer.setLayout(new BoxLayout(addVipPlayer,BoxLayout.Y_AXIS));

addVipPlayer.setPreferredSize(new Dimension(230, 265));

addVipPlayer.setBackground(Color.yellow);

JLabel heading = new JLabel("Adding a regular player");

heading.setAlignmentX(CENTER_ALIGNMENT);

JLabel money = new JLabel("Money the player's have:");

money.setAlignmentX(CENTER_ALIGNMENT);

moneyField = new JTextField();

moneyField.setMaximumSize(getPreferredSize());

JLabel playerId = new JLabel("Player's id:");

playerId.setAlignmentX(CENTER_ALIGNMENT);

idField = new JTextField();

idField.setMaximumSize(getPreferredSize());

JLabel playerName = new JLabel("Player's name:");

playerName.setAlignmentX(CENTER_ALIGNMENT);

nameField = new JTextField();

nameField.setMaximumSize(getPreferredSize());

addVipButton = new JButton("Add");

addVipButton.setAlignmentX(CENTER_ALIGNMENT);

addVipButton.addActionListener(new addButtonListener());

addVipPlayer.add(heading);

addVipPlayer.add(Box.createRigidArea(new Dimension(0,20)));

addVipPlayer.add(money);

addVipPlayer.add(moneyField);

addVipPlayer.add(playerId);

addVipPlayer.add(idField);

addVipPlayer.add(playerName);

addVipPlayer.add(nameField);

addVipPlayer.add(addVipButton);

add(addVipPlayer);

updateUI();

}

public class ButtonListener implements ActionListener{

public void actionPerformed(ActionEvent event){

if(event.getSource() == addAPlayer){

remove(menuPanel);

updateUI();

add(addAPlayerPanel());

updateUI();

}else if(event.getSource() == playerButton){

remove(addAPlayerPanel);

updateUI();

addRegularPlayer();

}else if( event.getSource() == vipPlayerButton){

remove(addAPlayerPanel);

updateUI();

addVipPlayer();

}

}

}

public class addButtonListener implements ActionListener{

public void actionPerformed(ActionEvent event){

if(event.getSource() == addRegularButton){

availablePlayers.add(new Player(Integer.parseInt(moneyField.getText()),false));

remove(addRegularPlayer);

updateUI();

add(menuPanel);

updateUI();

}else if(event.getSource() == addVipButton){

availablePlayers.add(new VipPlayer(Integer.parseInt(moneyField.getText()),true, Integer.parseInt(idField.getText()), nameField.getText()));

System.out.println(availablePlayers);

remove(addVipPlayer);

updateUI();

add(menuPanel);

updateUI();

}

}

}

}

}

-------------------------------------------------------------------------------------------------------------------------------

Bets.java

---------------------------------------------------

public class Bets {

private int betNumber, betAmount;

private String betColor;

private Boolean isColor;

private int chip1, chip5, chip25, chip100;

public Bets(String color, int amount,int chip1, int chip5, int chip25, int chip100,Boolean colorBet)

{

betColor = color;

betAmount = amount;

this.chip1 = chip1;

this.chip5 = chip5;

this.chip25 = chip25;

this.chip100 = chip100;

isColor = colorBet;

}

public Bets(int number, int amount,int chip1, int chip5, int chip25, int chip100, Boolean colorBet)

{

betNumber = number;

betAmount = amount;

this.chip1 = chip1;

this.chip5 = chip5;

this.chip25 = chip25;

this.chip100 = chip100;

isColor = colorBet;

}

public Boolean isColor(){

return isColor;

}

public int getBetAmount()

{

return betAmount;

}

public int getBetNumber()

{

return betNumber;

}

public String getBetColor()

{

return betColor;

}

public int getChip1() {

return chip1;

}

public int getChip5() {

return chip5;

}

public int getChip25() {

return chip25;

}

public int getChip100() {

return chip100;

}

}

-------------------------------------------------------------------------------------------------

Chips.java

-------------------------------------------

import javax.swing.JTextArea;

public class Chips {

protected int chip1, chip5, chip25, chip100;

protected int betChip1 = 0, betChip5 = 0, betChip25 = 0, betChip100 = 0; //to hold the chips for a bet

protected int payChip1 = 0, payChip5 = 0, payChip25 = 0, payChip100 = 0; //to hold the paied chips

protected int copyChip100,copyChip25, copyChip5, copyChip1 ; //to help in finding if a combination exists

public Chips(int hundreds, int twentyFives, int fives, int ones)

{

chip100 = hundreds;

chip25 = twentyFives;

chip5 = fives;

chip1 = ones;

}

public Chips() //Constructor for player

{

chip100 = 0;

chip25 = 0;

chip5 = 0;

chip1 = 0;

}

public int value()

{

return chip100 * 100 + chip25 * 25 + chip5 * 5 + chip1 * 1;

}

public void transfer(Chips tableChips, int amount) //transfer chips between player & table, +amount = player to table, -amount = table to player

{

int amountLeft = Math.abs(amount), count, x = amount / Math.abs(amount);

Chips chipSupply = x < 0 ? tableChips : this;

if (chipSupply.value() >= amountLeft)

{

for (count = amountLeft / 100; count > 0; count--)

{

if (chipSupply.hasChip(100,1))

{

tableChips.chip100+= x;

chip100-= x;

amountLeft-= 100;

}

else break;

}

for (count = amountLeft / 25; count > 0; count--)

{

if (chipSupply.hasChip(25,1))

{

tableChips.chip25+= x;

chip25-= x;

amountLeft-= 25;

}

else break;

}

for (count = amountLeft / 5; count > 0; count--)

{

if (chipSupply.hasChip(5,1))

{

tableChips.chip5+= x;

chip5-= x;

amountLeft-= 5;

}

else break;

}

for (count = amountLeft; count > 0; count--)

{

if (chipSupply.hasChip(1,1))

{

tableChips.chip1+= x;

chip1-= x;

amountLeft--;

}

}

}

}

//Chip change when a lower tier chip runs out and a higher tier chip is available

public Boolean change(Chips tableChips,JTextArea all, Integer playerNum)

{

if (copyChip25 == 0 && copyChip100 > 0 && tableChips.hasChip(25,4))

{

chip100--;

copyChip100--;

tableChips.chip100++;

tableChips.chip25-= 4;

chip25+= 4;

copyChip25 += 4;

all.append("Player "+ playerNum + " exchanged $100 chip with 4 $25 chips. ");

return true;

}else if (copyChip5 == 0 && copyChip25 > 0 && tableChips.hasChip(5,5))

{

chip25--;

copyChip25--;

tableChips.chip25++;

tableChips.chip5-= 5;

chip5+= 5;

copyChip5 += 5;

all.append("Player "+ playerNum + " exchanged $25 chip with 5 $5 chips. ");

return true;

}else if (copyChip1 == 0 && copyChip5 > 0 && tableChips.hasChip(1,5))

{

chip5--;

copyChip5--;

tableChips.chip5++;

tableChips.chip1-= 5;

chip1+= 5;

copyChip5 += 5;

all.append("Player "+ playerNum + " exchanged $5 chip with 5 $1 chips. ");

return true;

}else

return false;

}

public boolean hasChip(int chipType, int amount) //Chip check

{

switch (chipType)

{

case 100: return chip100 >= amount ;

case 25: return chip25 >= amount;

case 5: return chip5 >= amount;

case 1: return chip1 >= amount;

default: return false;

}

}

public void buy(Chips tableChips) //Player buyin and rebuy

{

if (tableChips.chip25 >= 2 && tableChips.chip5 >= 5 && tableChips.chip1 >= 25)

{

chip25 += 2;

chip5 += 5;

chip1 += 25;

tableChips.chip25 -= 2;

tableChips.chip5 -= 5;

tableChips.chip1 -= 25;

}

}

//to see if a player has the sufficient chips for the bet

public Boolean betPossibleCombination(int playerNum, int amount, JTextArea all, Chips tableChips){

betChip1 = betChip5 = betChip25 = betChip100 = 0;

copyChip100 = chip100;

copyChip25 = chip25;

copyChip5 = chip5;

copyChip1 = chip1;

for(int i = amount / 100; i >= 1; i--){

if(copyChip100 >= 0){

copyChip100--;

betChip100++;

amount -= 100;

}

}

for(int i = amount / 25; i >= 1; i--){

if(copyChip25 >= 1){

copyChip25--;

betChip25++;

amount -= 25;

}else{

if(change(tableChips, all, playerNum)) i++;

}

}

for(int i = amount /5 ; i >= 1; i--){

if(copyChip5 >= 1){

copyChip5--;

betChip5++;

amount-= 5;

}else{

if(change(tableChips, all, playerNum)) i++;

}

}

for(int i = amount ; i >= 1; i--){

if(copyChip1 >= 1){

copyChip1--;

betChip1++;

amount--;

}else{

if(change(tableChips, all, playerNum)) i++;

}

}

if(amount == 0)

return true;

else

return false;

}

//to see if a table has the sufficient chips to pay the player

public Boolean payPossibleCombination(int amount){

payChip1 = payChip5 = payChip25 = payChip100 = 0;

copyChip100 = chip100;

copyChip25 = chip25;

copyChip5 = chip5;

copyChip1 = chip1;

for(int i = amount / 100; i >= 1; i--){

if(copyChip100 >= 1){

copyChip100--;

payChip100++;

amount -= 100;

}

}

for(int i = amount / 25; i >= 1; i--){

if(copyChip25 >= 1){

copyChip25--;

payChip25++;

amount -= 25;

}

}

for(int i = amount /5 ; i >= 1; i--){

if(copyChip5 >= 1){

copyChip5--;

payChip5++;

amount-= 5;

}

}

for(int i = amount ; i >= 1; i--){

if(copyChip1 >= 1) {

copyChip1--;

payChip1++;

amount--;

}

}

if(amount == 0)

return true;

else

return false;

}

public String toString()

{

String result = " $100 chips: " + chip100 + " ";

result += " $25 chips: " + chip25 + " ";

result += " $5 chips: " + chip5 + " ";

result += " $1 chips: " + chip1 + " ";

return result;

}

}

--------------------------------------------------------------------------------------------------------

Game.java

---------------------------------------------

import java.util.ArrayList;

import javax.swing.JTextArea;

public class Game {

private String gameId;

private int minBet , maxBet;

private final int MAX_PLAYERS = 4;

private int currentRound;

private int cash;

private ArrayList transaction = new ArrayList();

private ArrayList players = new ArrayList();

private int houseWins;

private int houseLoses;

private Wheel wheel;

private Chips chips;

private int lastPrinted;

public Game(String id, int minimumBet, int maximumBet, Chips chips ){

gameId = id;

minBet = minimumBet;

maxBet = maximumBet;

this.chips = chips;

cash = 0;

wheel = new Wheel();

houseWins = 0;

houseLoses = 0;

currentRound = 1;

lastPrinted = 0;

}

public String getGameId(){

return gameId;

}

public int getMaxBet(){

return maxBet;

}

public int getMinBet(){

return minBet;

}

public int currentPlayers(){

return players.size();

}

public Player getPlayer(int index){

return players.get(index);

}

public ArrayList getTransactions(){

return transaction;

}

public Chips getTableChips(){

return chips;

}

public String spin(){

wheel.spin();

return wheel.toString();

}

public void pay(JTextArea all){

for(int i= 0; i < players.size(); i++)

{

players.get(i).pay(i+1,wheel.getPosition(),wheel.getColor() ,chips , transaction);

}

all.append("Trans Player BAmount ($100 $25 $5 $1) BType pay ($100 $25 $5 $1) ");

for(int i =lastPrinted; i < transaction.size() ; i++)

{

all.append(transaction.get(i).toString() +" ");

if(transaction.get(i).getPayAmount() == 0)

{

houseWins += transaction.get(i).getBetAmount();

}else

{

houseLoses += (transaction.get(i).getPayAmount() - transaction.get(i).getBetAmount());

}

}

lastPrinted = transaction.size();

}

public void addPlayer(Player player)

{

players.add(player);

}

public void removePlayer(int index)

{

players.remove(index);

}

public void anyBuyins(JTextArea all)

{

for(int i = 0; i < players.size(); i++)

{

if(players.get(i).getChipsValue() == 0 && players.get(i).getMoney() >= 100)

{

players.get(i).buyIn(chips);

all.append("Player " + (i +1) + " exchanged $100 for 2 $25-chips, 5 $5-chips, 25 $1-chip ");

}

}

}

public void updateRound()

{

currentRound++;

}

public int getCurrentRound()

{

return currentRound;

}

public String toString(){

String result ="";

result += "The game's id is: " + gameId;

result += " Number of Players: " + players.size();

result += " Current balance of the table is: $" + (chips.value() + cash) + " ";

result += " Cash: $" + cash + " ";

result += chips;

return result;

}

public String comboString()

{

String result = ("Min Bet: $" + minBet + " Max Bet: $" + maxBet);

return result;

}

public String initialBalance(){

String result = "";

result +="Initial Balance of the table: $" + (chips.value() + cash) + " ";

result += " Cash: $" + cash + " ";

result += chips + " ";

return result;

}

public String endingBalance(){

String result = "";

result +="Ending Balance of the table: $" + (chips.value() + cash);

result += " Cash: $" + cash + " ";

result += chips;

return result;

}

public String balanceReport(){

String result = "Table lost money is: $" + houseLoses;

result += " Table won money is: $" + houseWins +" ";

return result;

}

}

----------------------------------------------------------------------------------------------

GameFile.java

-------------------------------------------

import java.io.*;

import java.util.ArrayList;

import java.util.Scanner;

public class GameFile {

private static String gameVersion;

public static void load(ArrayList availGames, ArrayList availPlayers) throws IOException

{

Scanner fileScan = new Scanner(new File("games.txt"));

Chips tableChips;

int money;

char vip;

gameVersion = fileScan.next();

int count = fileScan.nextInt();

for (int i = 1; i <= count; i++)

availGames.add(new Game(gameVersion + Integer.toString(i), fileScan.nextInt(), fileScan.nextInt(), tableChips = new Chips(fileScan.nextInt(),fileScan.nextInt(),fileScan.nextInt(),fileScan.nextInt())));

fileScan = new Scanner(new File("players.txt"));

while (fileScan.hasNextLine())

{

vip = fileScan.next().charAt(0);

money = fileScan.nextInt();

if (vip == 'N')

availPlayers.add(new Player(money, false));

else if (vip == 'Y')

availPlayers.add(new VipPlayer(money, true, fileScan.nextInt(), fileScan.next() + " " + fileScan.next()));

}

fileScan.close();

}

public static void write(ArrayList gamesToBeLogged) throws IOException

{

FileWriter fileWrite = new FileWriter(new File("log.txt"));

for(Game g:gamesToBeLogged) {

fileWrite.write(g + " ");

fileWrite.write("The transactions for this game are: ");

fileWrite.write(" Trans Player BAmount ( $100 $25 $5 $1) BType pay ( $100 $25 $5 $1) ");

for (Transaction i : g.getTransactions())

fileWrite.write(i + " ");

fileWrite.write(g.balanceReport() + " ");

}

fileWrite.close();

}

public static String getVersion()

{

return gameVersion;

}

}

------------------------------------------------------------------------------------------------------

Person.java

------------------------

public interface Person {

public void bet(String color, int amount, Boolean colorBet, Chips table);

public void bet(int number, int amount, Boolean colorBet, Chips table);

}

------------------------------------------------------------------------------------------------------

Player.java

--------------------------------------------------

import javax.swing.*;

import java.util.ArrayList;;

public class Player implements Person

{

protected int money = 0;

private int winAmount = 0, loseAmount = 0;

protected Chips chip = new Chips();

private boolean vip;

private ArrayList bets = new ArrayList(); //Ultimately stored as integer (1-36, -1 for red, -2 for black)

public Player(int cash, boolean vipStatus)

{

money = cash;

vip = vipStatus;

}

public int getMoney()

{

return money;

}

public Chips getChips()

{

return chip;

}

public boolean isVIP()

{

return vip;

}

public void buyIn(Chips tableChips)

{

if (money >= 100)

{

chip.buy(tableChips);

money -= 100;

}

}

public int getChipsValue()

{

return chip.value();

}

public void bet(String color, int amount, Boolean colorBet, Chips table) //color is either "RED" or "BLACK" in all cap

{

bets.add(new Bets(color, amount,chip.betChip1, chip.betChip5, chip.betChip25, chip.betChip100, colorBet));

chip.transfer(table, amount);

}

public void bet(int number, int amount, Boolean colorBet, Chips table)

{

bets.add(new Bets(number, amount,chip.betChip1, chip.betChip5, chip.betChip25, chip.betChip100, colorBet));

chip.transfer(table, amount);

}

public void pay(int playerNum, int ballPosition, String color, Chips tableChips, ArrayList transactionArrayList)

{

for(int i = 0 ; i < bets.size() ; i++)

{

if(bets.get(i).isColor())

{

if(bets.get(i).getBetColor().equals(color))

{

int winAmount = 2 * bets.get(i).getBetAmount();

this.winAmount += bets.get(i).getBetAmount();

if(tableChips.payPossibleCombination(winAmount))

{

chip.transfer(tableChips, winAmount * -1);

transactionArrayList.add(new Transaction(transactionArrayList.size()+1,playerNum,bets.get(i) ,winAmount ,tableChips.payChip1,tableChips.payChip5 ,tableChips.payChip25,tableChips.payChip100, bets.get(i).getBetColor()));

bets.remove(i);

i--;

}else

{

System.out.println("The table needs change.");

}

}else

{

loseAmount+= bets.get(i).getBetAmount();

transactionArrayList.add(new Transaction(transactionArrayList.size()+1,playerNum,bets.get(i) ,0 ,0,0,0,0, bets.get(i).getBetColor()));

bets.remove(i);

i--;

}

}else

{

String betType = bets.get(i).getBetNumber() == -1 ? "00" : "" + bets.get(i).getBetNumber();

if(bets.get(i).getBetNumber() == ballPosition)

{

int winAmount = 35 * bets.get(i).getBetAmount();

this.winAmount += 34 * bets.get(i).getBetAmount();

if(tableChips.payPossibleCombination(winAmount)){

chip.transfer(tableChips, winAmount * -1);

transactionArrayList.add(new Transaction(transactionArrayList.size()+1,playerNum,bets.get(i) ,winAmount ,tableChips.payChip1,tableChips.payChip5 ,tableChips.payChip25,tableChips.payChip100, betType));

bets.remove(i);

i--;

} else

{

System.out.println("The table needs change.");

}

}else

{

loseAmount+= bets.get(i).getBetAmount();

transactionArrayList.add(new Transaction(transactionArrayList.size()+1,playerNum,bets.get(i) ,0 ,0,0,0,0,betType));

bets.remove(i);

i--;

}

}

}

}

public ArrayList getBets()

{

return bets;

}

public String getId()

{

return " ";

}

public int getWinAmount()

{

return winAmount;

}

public String toString()

{

return "Not VIP \tCash: $" + money + " \tChip value: $" + chip.value() + " ";

}

}

----------------------------------------------------------------------------------------------------------

Transaction.java

--------------------------------------------

public class Transaction {

private int bAmount;

private int playerId;

private String bType;

private int betChips1d , betChips5d, betChips25d, betChips100d;

private int payChips1d, payChips5d, payChips25d, payChips100d;

private int transactionId;

private int winAmount;

public Transaction(int id, int player, Bets bet, int pay ,int pChips1d ,int pChips5d ,int pChips25d ,int pChips100d ,String betType){

transactionId = id;

bAmount = bet.getBetAmount();

playerId = player;

if(betType.equals("BLACK"))

bType = "BLK";

else if(betType.equals("RED"))

bType = "RED";

else

bType = betType;

betChips1d = bet.getChip1();

betChips5d = bet.getChip5();

betChips25d = bet.getChip25();

betChips100d = bet.getChip100();

winAmount = pay;

payChips1d = pChips1d;

payChips5d = pChips5d;

payChips25d = pChips25d;

payChips100d = pChips100d;

}

public int getBetAmount() {

return bAmount;

}

public int getPayAmount() {

return winAmount;

}

public String toString(){

String transaction ="";

transaction += " " + transactionId + " " + playerId + " " + bAmount + " ( " + betChips100d + " " + betChips25d+ " "

+ betChips5d + " " + betChips1d +") " + bType + " " + winAmount + " ( " + payChips100d + " " + payChips25d + " " + payChips5d

+ " " + payChips1d +")";

return transaction;

}

}

------------------------------------------------------------------------------------------------------

VipPlayer.java

------------------------------------------------

public class VipPlayer extends Player implements Person{

private final int id;

private String name;

private final double vipReward = 0.05;

private int totalbets;

public VipPlayer(int cash, boolean vipStatus, int playerID, String playerName)

{

super(cash, vipStatus);

id = playerID;

name = playerName;

totalbets = 0;

}

public void bet(String color, int amount, Boolean colorBet, Chips table)

{

super.bet(color,amount,colorBet,table);

totalbets += amount;

}

public void bet(int number, int amount, Boolean colorBet, Chips table)

{

super.bet(number, amount, colorBet, table);

totalbets += amount;

}

public String getId()

{

String result = "(" +id+")";

result = String.format("%8s",result);

return result;

}

public int getTotalbets() {

return totalbets;

}

public int awardAmount(){

int cashBack = (int) Math.ceil(totalbets * vipReward);

money += cashBack;

return cashBack;

}

public String getName()

{

return name;

}

public double getVipReward()

{

return vipReward;

}

public String toString()

{

return name + " VIP \tCash: $" + money + " \tChip value: $" + chip.value() + " ";

}

}

------------------------------------------------------------------------------------------------------

Wheel.java

-----------------------------------------------------------

import java.util.Random;

public class Wheel

{

// public name constants -- accessible to others

public final static int BLACK = 0; // even numbers

public final static int RED = 1; // odd numbers

public final static int GREEN = 2; // 00 OR 0

public final static int NUMBER = 3; // number bet

public final static int MIN_NUM = 1; // smallest number to bet

public final static int MAX_NUM = 36; // largest number to bet

private final static int MAX_POSITIONS = 38; // number of positions on wheel

private final static int NUMBER_PAYOFF = 35; // payoff for number bet

private final static int COLOR_PAYOFF = 2; // payoff for color bet

private static int ballPosition; // 00, 0, 1 .. 36

private String COLOR ;

public void spin()

{

Random rand = new Random();

ballPosition = rand.nextInt(MAX_POSITIONS) - 1;

//ballPosition = 2; for testing

//COLOR = "BLACK"; for testing

if(ballPosition == -1 || ballPosition == 0)

COLOR = "GREEN";

else if(ballPosition %2 == 0)

COLOR = "BLACK";

else if(ballPosition %2 != 0)

COLOR = "RED";

}

public String getColor(){

return COLOR;

}

public int getPosition(){

return ballPosition;

}

public String toString(){

String result = "============================= The ball landed on ";

if (ballPosition == 0)

{

result += ballPosition + " (Green) ";

}

else if (ballPosition == -1)

{

result +="00 (Green) ";

}

else if (ballPosition % 2 == 0)

{

result += ballPosition + " (Black) ";

}

else

{

result += ballPosition + " (Red) ";

}

result +="============================= ";

return result;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is an enterprise network?

Answered: 1 week ago

Question

What types of support from others were most helpful?

Answered: 1 week ago