Hello everyone,
My teacher is having us do a bridge (cardgame) program in java. This is what I have so far. He set up the methods so we have to use those. What is contained in the methods, I have written. I'm not sure how I'm supposed to get the data back to main from the methods, or even if I'm supposed to. If I am, I can't because they are void. So, I'm not really sure what the point of them would be.
Actually - here's the original blank slate that we started with:
My teacher is having us do a bridge (cardgame) program in java. This is what I have so far. He set up the methods so we have to use those. What is contained in the methods, I have written. I'm not sure how I'm supposed to get the data back to main from the methods, or even if I'm supposed to. If I am, I can't because they are void. So, I'm not really sure what the point of them would be.
import java.util.Random; //required for random numbers
public class bridge
{
static String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
static String[] ranks = {"2", "3", "4", "5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King", "Ace"};
public static void main(String[] args)
{
int[] deck = new int[52];
unwrap(deck);
shuffle(deck);
final int CARDS_PER_HAND = 13;
int[] north = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 0);
showHand(north, "North");
int[] east = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 1);
showHand(east, "East");
int[] south = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 2);
showHand(south, "South");
int[] west = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 3);
showHand(west, "West");
}
public static void unwrap(int[] pack)
// Initialize the deck - creates an array for the deck that is 52 cards long (0-51)
{
for(int i = 0; i < pack.length; i++)
pack[i] = i;
}
public static void shuffle(int[] deck)
//Shuffle the deck
{
for (int i = 0; i < deck.length; i++)
{
int index = (int) (Math.random() * deck.length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}
}
public static int[] deal(int[] deck, int n, int offset)
//Deal “n” cards offset from the beginning of the deck. Return the hand dealt as an array of integers.
{
return deck;
}
public static void showHand(int[] hand, String player)
//Show a player’s hand sorted by suit and rank. The name of the player is passed as a string.
{
}
}
Actually - here's the original blank slate that we started with:
public class bridge
{
static String[] suits = {"Spades", "Hearts", "Diamonds", "Clubs"};
static String[] ranks = {"2", "3", "4", "5", "6", "7", "8",
"9", "10", "Jack", "Queen", "King", "Ace"};
public static void main(String[] args)
{
int[] deck = new int[52];
unwrap(deck);
shuffle(deck);
final int CARDS_PER_HAND = 13;
int[] north = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 0);
showHand(north, "North");
int[] east = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 1);
showHand(east, "East");
int[] south = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 2);
showHand(south, "South");
int[] west = deal(deck, CARDS_PER_HAND, CARDS_PER_HAND * 3);
showHand(west, "West");
}
public static void unwrap(int[] pack)
// Initialize the deck
{
}
public static void shuffle(int[] deck)
//Shuffle the deck
{
}
public static int[] deal(int[] deck, int n, int offset)
//Deal “n” cards offset from the beginning of the deck.
{
}
public static void showHand(int[] hand, String player)
//Show a player’s hand sorted by suit and rank. The name of the player is passed as a string.
{
}
}