okay so I did the card.java
public class Card {
private int Value;
private int Suit;
/*1 - club ♣
*2 - diamond ♦
*3 - spade ♠
*4 - heart ♥
*/
String club;
public Card()
{
Value=1;
Suit = 1;
}
public Card(int v, int s)
{
Value = v;
Suit=s;
}
public int getValue()
{
return Value;
}
public int getSuit()
{
return Suit;
}
public String getName()
{
String name = "";
if(Value == 11)
name += "J";
if(Value == 12)
name += "Q";
if(Value == 13)
name += "K";
if(Value == 1)
name += "A";
if(Suit == 1)
name += "C♣";
if(Suit == 2)
name += "D♦";
if(Suit == 3)
name += "S♠";
if(Suit == 1)
name += "H♥";
return name;
}
}
I don't know how to do the bet class, bankroll class, deck class, hand class and player class.
But I tried to do BankRoll, deck and Bet but I don't know if these are correct. here are the codes:
[[Here's what my teacher statement: Bet Class
Information (variables):
- Amount of Bet
Actions (methods):
- Return amount of bet
- Change amount of bet
]]
public class Bet {
private int Bet;
public Bet()
{
Bet=1;
}
public Bet(int b)
{
Bet = b;
}
public int getBet()
{
return Bet;
}
public void ChangeBet()
{
}
[[For :Bankroll Class
Information (variables):
- Balance
Actions (methods):
- Update current number of credits (increase or decrease), can be set
- Return the number of credits
- Change the number of credits (sets the balance, used mainly to set the starting balance)
]]
public class BankRoll {
private int Balance;
public BankRoll(int b)
{
Balance=b;
}
public int getBankRoll()
{
return Balance;
}
}
[[Deck Class
Information (variables):
- An array of cards
- The current card (this simulates the top card)
Actions (methods):
- Deal
- Shuffle]]
public class Deck {
private int[] myDeck;
public static final int NUMCARDS = 52;
public Deck()
{
myDeck = new int[NUMCARDS];
for(int i = 0; i<NUMCARDS; i++)
myDeck[i] = 1;
}
private void current(int[] a, int i, int j)
{
int temp = a[i];
a[i] = a[j];
a[j]=temp;
}
public void shuffle()
{
int num;
for(int i = NUMCARDS - 1; i>0; i--)
{
num = (int)(Math.random()*(1+i));
current(myDeck, i, num);
}
}
}
here's what he said how to do the hand class:
[[Hand Class
Information (variables):
- An array of cards
- A Deck
Actions (methods):
- New Hand - 5 cards
- Discard & Replace
- Score - return the highest hand
]]
[[here's what he said on how to do the player]]
Hand Class
Information (variables):
- None specific to the player class, a Scanner is needed
Actions (methods):
***I've included the the return type and parameters for each method needed to work with the Game class I provided
- void welcome() - displays a welcome message
- int setBankRoll() - asks for the number of credits to deposit, returns that value
- int menu() - displays a menu with 3 choices - 1: make a bet and play, 2: add more credits, 3: quit and cash out
- int bet() - asks user to place a bet, returns that value
- void showScore(int payout) - displays the outcome of the hand (Royal Flush,
- void showBalance(int balance) - displays the balance of the credits
- void showHand(Card[] cards) - displays the hand
- int[] discard(Card[] cards) - asks to discard each card, returns and array with responses (1 for yes, 2 for no)
- void showWinnings(int winnings) - displays credits won on hand
- void endGame(int balance) - displays an ending message, including final balance ]]
here's what I have done:
public class Player {
public void welcome()
{
System.out.println("Welcome, Let's play Poker");
}
private int setBankRoll()
{
return 0;
}
private int menu()
{
return 0;
}
private int bet()
{
return 0;
}
private void showScore(int payout)
{
}
private void showBalance(int balance)
{
}
public void showHand(Card[] cards)
{
}
public int[] discard(Card[] cards)
{
return null;
}
public void showWinnings(int winnings)
{
}
public void endGame(int balance)
{
}
}
I do have the game class
here is the Game class:
public class Game {
private Hand hand;
private BankRoll bank;
private Bet bet;
private Player player;
public Game()
{
hand = new Hand();
bank = new BankRoll();
bet = new Bet();
player = new Player();
}
public void startGame()
{
int choice;
int winnings;
int payout;
int discards[] = {0, 0, 0, 0, 0};
player.welcome(); //Displays a welcome message
bank.changeBankRoll(player.setBankRoll()); //Asks user to deposit credits
choice = player.menu(); //Asks user to choose one of 3 actions - play, add credits, quit
while(choice != 3) //repeats until user quits
{
if (choice == 1) //user chooses to play
{
bet.setBet(player.bet()); //Asks user to place a bet
bank.changeBankRoll(-bet.getBet()); //Deducts the bet from the bankroll
hand.newHand(); //Deals a new hand
player.showHand(hand.getHand()); //Displays the hand to the user
discards = player.discard(hand.getHand()); //Gets discards from user as an array - discards[#] = 1 for a discard, 2 to not discard
for(int c = 0; c < discards.length; c++) //Loops through discard array
if(discards[c] == 1)
hand.discard(c); //Discards specific card
player.showHand(hand.getHand()); //Displays hand after discards
payout = hand.score(); //Calculates payout odds based on hand score - payout = 250 for royal flush, etc.
player.showScore(payout); //Displays the result of the hand
winnings = payout * bet.getBet(); //Calculates amount user wins
if(payout != 0) //Tests if user won
bank.changeBankRoll(winnings + bet.getBet()); //Adds winnings to the bankroll
player.showWinnings(winnings); //Displays winnings to user
player.showBalance(bank.getBankRoll()); //Displays bankroll balance to user
}
else
{
bank.changeBankRoll(player.setBankRoll()); //Asks user how many credits to add to bankroll
}
choice = player.menu(); //Displays menu of choices again
}
player.endGame(bank.getBankRoll()); //Displays amount of credits user has won when they quit
}
}
}
Please please please help on how to do them, and please correct the wrong ones. I am having a trouble in understanding java.