Question
Java Main topics: Writing Classes Declaring / Using Instance Variables Writing Instance Methods Accessors and Mutators Constructors public vs private static vs non-static Program Specification:
Java
Main topics:
Writing Classes
Declaring / Using Instance Variables
Writing Instance Methods
Accessors and Mutators
Constructors
public vs private
static vs non-static
Program Specification:
You are to write a Class Deck which emulates a full deck of playing cards. That is 4 suits (Clubs, Spades, Hearts, and Diamonds) and 13 ranks (Ace, 2, 3, 4, 5, 6, 7, 8, 9, Jack, Queen, King) in each suit. This of course makes for a total of 52 playing cards in the deck.
Mandatory Instance variables:
private Card[] deck = new Card[52];
private int cardsDealt;
Mandatory Instance methods:
public Deck() // constructor
// set each element of deck to a unique Card object,
// and sets cardsDealt to zero.
public int getCardsDealt() // accessor
// return the value of cardsDealt.
private void setCardsDealt(int cardsDealt) // mutator
// sets cardsDealt specified value (cardsDealt)
public boolean emptyDeck()
// returns wheather or not all the cards in deck
// have already been dealt (cardsDealt == 52).
public void collectCards()
// set cardsDealt to zero.
public void collectCards(int cardCnt)
// decrement cardsDealt by cardCnt.
public Card dealCard()
// if emptyDeck() is false ...
// returns the card at location cardsDealt in deck,
// and increments cardsDealt by 1.
// else ...
// returns null
public void shuffleDeck()
// apply 100 random card swaps within deck
public void shuffleDeck(int swapCnt)
// apply swapCnt random card swaps within deck
You are also to write a Driver Class DeckDriver to test your Deck class.
Mandatory Functionality:
Your driver class must minimally print all the cards in the deck in the random order that they are dealt. Such as in Programs 1, 2, and 3.
Rules and Requirements:
All access of the instance variable cardsDealt, by the other instance methods is made via its accessor and mutator.
Notes and Hint:
1. You will need to copy your Card.java file (from Program 3) into your working directory / project in order to compile your deck class.
2. You should be able to re-write your driver class from Program 3 into your driver class with minimal modification / effort.
Program 3 Card
class Card { private String suit; private String rank;
public Card(String suit, String rank) { this.suit = suit; this.rank = rank; }
public Card() { this.rank = "A"; this.suit = "C"; }
public String getSuit() { return suit; }
public String getRank() { return rank; }
public void setSuit(String suit) { this.suit = suit; }
public void setRank(String rank) { this.rank = rank; }
public String toString() { return this.suit + this.rank; }
public Card clone() { return this; }
public boolean equals(Card guest) { return suit.equalsIgnoreCase(guest.suit) && rank.equalsIgnoreCase(guest.rank); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started