Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java need help... any class... any help A company intends to offer various versions of roulette game and it wants you to develop a customized

Java need help... any class... any help

A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able to keep track of its id, chips, money, active players, and transactions. Available chips for each game shall consist of $1, $5, $25, and $100. Each transaction shall consist of a transaction number, player number (seat number), and relevant betting information. A player can be a regular player or a VIP player. Each player keeps track of his/her own money and chips. A VIP player has a 4-digit id and name as well; the system also keeps track of all bets and awards 5% cash back credit rounding up to a whole dollar of all the bets to a VIP player when he or she leaves the game. A player can determine his/her winning amount when he or she leaves the game (include cash back credit if applicable). The system will load all games with data from an input data file upon startup. The user (game operator) will be able to conduct one selected game at a time. The main menu should contain the following options:

Main Menu

1. Select a game

2. Add a player to the list

3. Quit

If option 1 is chosen, the user will be prompted to select a game from a list of available games and a game menu is available as shown below. When option 2 is selected, obtain necessary data and add a new player to the list of available players. When option 3 from the main menu is selected, print complete information for each game to a new text file before the program is terminated

. Game Menu

1. Add a player to the game

2. Play one round

3. Return to the main menu

For option 1, you need to add the next player from a list of available players to the game. When option 2 is selected, play one round similar to project 2 and you need to exchange cash for chips for a player (if applicable), remove a player, and provide winning or losing information about the player that no longer wants to play. If option 3 is selected, return to the main menu. See below for a sample input/output.

Initialize games. Please wait ... All games are ready.

Available games: 100A1, 100A2

Main Menu 1. Select a game

2. Add a player to the list

3. Quit Option --> 1

Select a game --> 100A1

Game Menu

1. Add a player to the game

2. Play one round

3. Return to main menu

. . .

Player 1 left the game with winning amount of $10

. . . .

Main Menu

1. Select a game

2. Add a player to the list

3. Quit Option --> 2

Generating report ...

Shutting down all games.

Sample report for one session (only one player with one round):

Game: 100A1

Initial Balance: $9500

Cash: $0

$100 chips: 50

$25 chips: 100

$5 chips: 200

$1 chips: 1000

Player 1 exchanges $100 for 2 $25-chip, 5 $5-chip, 25 $1-chip

Round 1 (Red 13)

Trans Player BAmount ($100 $25 $5 $1) BType Pay ($100 $25 $5 $1)

1 1 10 ( 0 0 2 0) R 20 ( 0 0 4 0)

Ending Balance: $9490

Cash: $100

$100 chips: 50

$25 chips: 98

$5 chips: 193

$1 chips: 975

Losing amount for this session: $10

Game: 100A2 ...

There will be a data file, games.txt, contains information about the version, number of games, minimum bet, maximum bet, and available chips ($100, $25, $5, and $1). There will be another data file, players.txt, contains a list of available players, both regular players (N) and VIP players (Y). We will also make these assumptions as well:

Multiple games can be played and a game operator can switch back and forth between games.

Up to 4 players per game (seats 1 to 4).

Each buy-in (exchange cash for chips) is a multiple of $100. For each $100 buy-in, a player would get 2 $25 chips, 5 $5 chips, and 5 $1 chips.

A winning bet will be paid with largest denomination first (e.g., a winning bet of $35 would get 1 $25 chip and 2 $5 chips).

A player starts with cash when entering a new game and can leave a game with chips.

A player can place multiple bets per round (up to 3).

Each game starts with 0 in cash for the casino

Assume there are sufficient chips for each game unless doing extra credit.

Players will get on the list to play and they will not get off the list.

The input data files contain valid data. Analysis and Design Make sure you understand all the requirements.

Ask for clarifications and missing information before you move on to the design phase. You should refer back to project 2 for some requirements about the basic roulette game. Plan the user interface: menus (see above) and interaction for each player (see project 2), Come up with a design by drawing a class diagram showing use-a, has-a, and is-a relationships as applicable. Include as much attributes and behaviors as you can for each class. You should use pseudocode to document some complex behaviors. You should take advantage of aggregation and inheritance for this project. The program first loads data from games.txt, and players.txt. It then allows a game operator conducts each game and players to play the games. Print helpful messages to the screen so that we know what is going on. Make sure to utilize aggregation, inheritance, and polymorphism so that you will not need to do unnecessary work. Points will be deducted if you do not utilizing at least some useful OOP features. You might not be able to implement all features, but here is the order of important features:

1. Keep track of chips

2. Allow VIP players

3. Generate a summary report without transactions (ignore transactions)

4. Allow multiple bets per round for each player (can start with one bet)

5. Support multiple games (can start with one game)

6. Keep track of transactions and include transactions in report

7. Add a new player to the list of available players

games.txt

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

players.txt

N 100 Y 500 1234 Jane Smith Y 300 3455 John Smith N 500 Y 1000 9867 Hot Shot N 200 N 300

import java.util.*;

//************************************************************************

// Class Roulette contains the main driver for a roulette betting game.

//************************************************************************

class Roulette

{

private static int houseMoney = 0;

//=====================================================================

// Contains the main processing loop for the roulette game.

//=====================================================================

public static void main (String[] args)

{

Wheel Wheel1 = new Wheel();

Scanner scan = new Scanner(System.in);

Player player1 = new Player ("Jane", 100); // $100 to start for Jane

Player player2 = new Player ("Peter", 100);

boolean bl1 = true;

boolean bl2 = true;

System.out.println ("Author: Dasol Yang ");

Wheel.welcomeMessage();

while (bl1 || bl2)

{

// initiate the values

if(bl1)player1.makeBet(Wheel1);

if(bl2)player2.makeBet(Wheel1);

Wheel.Spin();

// check the boolean value

if(bl1)

{

//initiate the payment

player1.payment(Wheel1);

System.out.println ("Money available for " + player1.getName() + ": " + player1.getMoney());

// check weather play the game again

if(!player1.playAgain(scan))

{

bl1 = false;

}

}

// check the boolean value

if(bl2)

{

//initiate the payment

player2.payment(Wheel1);

System.out.println ("Money available for " + player2.getName() + ": " + player2.getMoney());

// check weather play the game again

if(!player2.playAgain(scan))

{

bl2 = false;

}

}

// check the boolean value

System.out.println();

}

System.out.println(player1.displayStatus());

System.out.println(player2.displayStatus());

System.out.printf("House %s: $%d", houseMoney > 0 ? "Wins" : "Losses", houseMoney);

System.out.println();

System.out.println ("Game over! Thanks for playing.");

}

public static void setHouseWins(int Winnings)

{

houseMoney += Winnings;

}

}

//////////////////////////////////////

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 = 10; // largest number to bet

// private name constants -- internal use only

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

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

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

// private variables -- internal use only

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

private static int color; // GREEN, RED, OR BLACK

//=====================================================================

// Presents welcome message

//=====================================================================

public static void welcomeMessage()

{

System.out.println("Welcome to a simple version of roulette game.");

System.out.println("You can place a bet on black, red, or a number.");

System.out.println("A color bet is paid " + COLOR_PAYOFF + " the bet amount.");

System.out.println("A number bet is paid " + NUMBER_PAYOFF + " the bet amount.");

System.out.println("You can bet on a number from " + MIN_NUM + " to " + MAX_NUM + ".");

System.out.println("Gamble responsibly. Have fun and good luck! ");

}

//=====================================================================

// Presents betting options

//=====================================================================

public static void betOptions()

{

System.out.println("Betting Options:");

System.out.println(" 1. Bet on black (even numbers)");

System.out.println(" 2. Bet on red (odd numbers)");

System.out.println(" 3. Bet on a number between " + MIN_NUM +

" and " + MAX_NUM);

System.out.println();

}

// method for spin the wheel

public static int Spin()

{

ballPosition= (int)(Math.random() * 12 + 1);

if(ballPosition < 11)

{

if(ballPosition % 2 == 0)

{

color = BLACK;

}

else

{

color = RED;

}

}

else

{

color = GREEN;

}

System.out.println("Result: "+ ((color < 1) ? "Black " : "Red ") + ballPosition);

return ballPosition;

}

// method for payoff

public int Payoff(int btAmt, int btType, int btNmbt)

{

if(color == GREEN)

{

return 0;

}

else if(btType == 1 && color == BLACK)

{

return btAmt * COLOR_PAYOFF;

}

else if( btType == 2 && color == RED)

{

return btAmt * COLOR_PAYOFF;

}

else if (btType == 3 && btNmbt == ballPosition)

{

return btAmt * NUMBER_PAYOFF;

}

else if(btType == 3 && btNmbt != ballPosition)

{

return 0;

}

else

{

return 0;

}

}

}

//////////////////////////////

import java.util.*;

class Player

{

private static final int RELOAD_AMOUNT = 100;

private int bet, money;

private String name;

private int betType, betNumber;

private int betNet;

private static int houseWins;

private Scanner scan = new Scanner(System.in);

//Wheel Wheel1 = new Wheel();

//=====================================================================

// The Player constructor sets up name and initial available money.

//=====================================================================

public Player (String playerName, int initialMoney)

{

name = playerName;

money = initialMoney;

} // constructor Player

//=====================================================================

// Returns this player's name.

//=====================================================================

public String getName()

{

return name;

} // method getName

//=====================================================================

// Returns this player's current available money.

//=====================================================================

public int getMoney()

{

return money;

} // method getMoney

public int getNet()

{

return betNet;

}

//=====================================================================

// Prompts the user and reads betting information.

//=====================================================================

public void makeBet(Wheel wheel)

{

System.out.println("How much to bet for " + name + ": ");

bet = scan.nextInt();

while(bet>money)

{

System.out.println("You can't bet more than what you have.");

System.out.println("Enter how much you want to bet.");

bet = scan.nextInt();

}

if(bet==money)

{

bet = money;

System.out.println("Betting it all in!");

}

money = money - bet;

Wheel.betOptions();

betType = scan.nextInt();

if(betType == 3)

{

while(true)

{

System.out.println("Enter a number between 1 to 10: ");

betNumber = scan.nextInt();

if(betNumber < Wheel.MIN_NUM || betNumber > Wheel.MAX_NUM)

{

System.out.println("You put a wrong number. Enter a number between 1 to 10");

}

else

{

break;

}

}

}

} // method makeBet

//=====================================================================

// Determines if the player wants to play again.

//=====================================================================

public boolean playAgain(Scanner scan)

{

String answer;

System.out.print (name + "Play again [y/n]? ");

answer = scan.next();

return (answer.equals("y") || answer.equals("Y"));

} // method playAgain

public void payment(Wheel wheel2)

{

int winnings = wheel2.Payoff(bet, betType, betNumber);

money += winnings;

if(winnings > 0)

{

betNet += (winnings-bet);

Roulette.setHouseWins(-(winnings-bet));

}

else

{

betNet -= bet;

Roulette.setHouseWins(bet);

}

if(money < 1)

{

Scanner scan = new Scanner(System.in);

System.out.println(name + ", you're out of money. Do you want to bet more? [Y/N] ");

String answer= scan.nextLine().toLowerCase();

if(answer.equals("y"))

{

System.out.println("You got another $100");

int RELOAD_AMOUNT = 100;

money += RELOAD_AMOUNT;

}

}

//setHouseWins(betNet);

//System.out.println("Testing to see how much is betNet keeping track of: " + betNet);

}

public String displayStatus()

{

if(betNet>=0)

{

return this.getName() + "total winning: " + betNet;

}

else

{

return this.getName() + "total losing: " + betNet;

}

}

}

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions