/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prog2;
/**
*
* @author ???
*/
public class Prog2 {
/**
* @param args the command line arguments
*/
public static void main(String [] args){
System.out.println(Rank.QUEEN);
Card card = new Card(Rank.QUEEN, Suit.SPADES);
System.out.println(card);
//System.out.println(card.toStringShort());
System.out.println("_____________________________");
/* Deck deck = new Deck();
deck.shuffle();
for (int i = 0; i < 50; ++i) {
System.out.println(deck.dealCard());
}
System.out.println(deck); //prints the remaining cards
System.out.println("_____________________________");
Shoe shoe = new Shoe(4);
shoe.shuffle();
for (int i = 0; i < 50; ++i) {
System.out.println(shoe.dealCard());
}
System.out.println("_____________________________"); */
}
}
class Card{ //outputs info for a single instance of a card
public String singleRank;
public String singleSuit;
public String Card(){
String test="of";
return test;
}
public Card(){}
// Item 1: a two arg constructor that passes in a rank and suit which will initialize the card.
//Item 2: a two arg constructor that takes two integer parameter, one representing a rank (from 0-12) and one representing a suit (from 0-3). Use these two variables to initialize the Rank and Suit instance variables.
public Card(int x, int y){
Rank instanceR = new Rank();
singleRank= instanceR.getName(x);
Suit instanceS = new Suit();
singleSuit= instanceS.getName(y);
}
//Item 3: getter methods for the Card class that return Rank and Suit.
//Item 4: a toString() method, which will return the value of the card as follows: Rank of Suit such as Two of Diamonds.
@Override
public String toString () {
return "This is the toString() method in the Card Class";
}
//Item 5: an equals method that will return true if both cards have the same rank and suit.
//Item 6: a toStringShort() method which will return the value of the card as follows: abbreviated Rank (no space) abbreviated Suit such as 2D.
} // end Card class
class Deck{ //simulates a deck of cards
//Item 1: a no arg constructor that stores a complete set of cards (13 cards in each suit). Hold the cards in an array of Card.
//Item 2: a method called shuffle, that will shuffle the 52 cards in the deck. Use java.util.Random to select your random numbers.
//Item 3: a method called dealCard, that returns the next card in the deck.
//Item 4: a method called getCardsRemaining(), which returns the number of remaining cards in the deck that have not been played.
//Item 5: a toString method, that will return a string with the remaining cards in the deck. Note toString() prints the abbreviated version of the card. Example: AD QS 4D 9H....
}
class Shoe{ //simulates storage of 2 to 8 decks of cards
// Create a no arg constructor that stores one deck of cards in the shoe.
//o Create a one arg constructor that takes in an integer that states the number of decks in the shoe.
//o Create a method called shuffle, that shuffles all the decks in the shoe.
//o Create a method called dealCard, that returns the next card in the shoe.
//o Create a method called getCardsRemaining(), which returns the number of remaining cards in the shoe that have not been played.
}
class Rank{
public Rank(){//initializes new instance
}
// Item 1: a private static array of Strings and initialize it to include the names of each rank ("Ace","Two",....."King")
private static String[] rankNames={"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
// Item 2: a private static array of Strings and initialize it to include the abbreviated rank name for each rank ("A","2","3",...,"Q","K").
private static String[] rankNameAbbrev={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
// Item 3: a private instance variable of type int that holds a value from 0-12 representing one of the 13 ranks
private static int rankIndex=0;
// Item 4: a public constructor with one integer parameter that is used to initialize the instance variable
public Rank(int enterRankIndex){ rankIndex=enterRankIndex; System.out.println("Rank marker"); }
// Item 5: a public getter that uses the instance variable to return the rank name as a String.
public String getName(int rankIndex)
{return rankNames[rankIndex]; }
// Item 6: a public getter that uses the instance variable to return the abbreviated rank name as a String
public String getAbbrev(int rankIndex)
{return rankNameAbbrev[rankIndex]; }
// Item 7: a private static array with 13 elements of type Rank and initialize it with Rank objects corresponding to each of the 13 indices. Create array of objects section 8.11
Rank[] rankArray = new Rank[13];
for(int i=0; i<rankArray.length; i++){
rankArray[i]= new Rank(i);
System.out.println("create Rank marker"); }
// Item 8: a public static getter that takes a single integer as a parameter and returns the corresponding Rank object from the static array
public static Rank getRank(Rank[] rankArray){
Rank outputRank = rankArray[rankIndex];
return outputRank;
}
// Item 9: List of Public Static Final Int variables representing the ranks
public static final int ACE=0;
public static final int TWO=1;
public static final int THREE=2;
public static final int FOUR=3;
public static final int FIVE=4;
public static final int SIX=5;
public static final int SEVEN=6;
public static final int EIGHT=7;
public static final int NINE=8;
public static final int TEN=9;
public static final int JACK=10;
public static final int QUEEN=11;
public static final int KING=12;
} // end Rank Class
class Suit{
public Suit(){//initializes new instance
}
// Item 1: a private static array of Strings and initialize it to include the names of the suits ("Hearts",...)
private static String[] suitNames={"Hearts","Spades","Diamonds","Clubs"};
// Item 2: a private static array of Strings and initialize it to include the abbreviated rank name for each suit ("H","S","D","C").
private static String[] suitNameAbbrev={"H","S","D","C"};
// Item 3: a private instance variable of type int that holds a value from 0-3 representing one of the 4 suits
private static int suitIndex=0;
// Item 4: a public constructor with one integer parameter that is used to initialize the instance variable
public Suit(int enterSuitIndex){ suitIndex=enterSuitIndex; }
// Item 5: a public getter that uses the instance variable to return the suit name as a String.
public String getName(int suitIndex)
{return suitNames[suitIndex]; }
// Item 6: a public getter that uses the instance variable to return the abbreviated suit name as a String
public String getAbbrev(int suitIndex)
{return suitNameAbbrev[suitIndex]; }
// Item 7: a private static array with 4 elements of type Suit and initialize it with Suit objects corresponding to each of the 4 indices. Create array of objects section 8.11
Suit[] suitArray = createSuitArray();
public static Suit[] createSuitArray(){
Suit[] suitArray= new Suit[4];
for(int i=0; i<suitArray.length; i++){
suitArray[i]= new Suit(i);
}
return suitArray;
}
// Item 8: a public static getter that takes a single integer as a parameter and returns the corresponding Suit object from the static array
public static Suit getSuit(Suit[] suitArray){
Suit outputSuit = suitArray[suitIndex];
return outputSuit;
}
// Item 9: List of Public Static Final Int variables representing the suits
public static final int SPADES = 1;
public static final int HEARTS = 0;
public static final int CLUBS = 3;
public static final int DIAMONDS = 2;
} // end suit class