|
Help Java project.
I know its horrible... I feel horrible about it; i'm still working on it but this Java project is killing me... Just so you know i dont have to know programing after this class, i just had a choice between 3 computer classes and picked the one i guess i'm worst at... I've done four major projects before this one. I average getting about 75% correct. We code in BlueJ...The reason i'm finally breaking down for help is it was due on November 21st. o well enough of my babble if ur going to help ur going to help; if not ur not.
Heres the assignment
Open the project cards containing your code for class PlayingCard and create the two new
classes in this project space:
Part 4: Implement class CardDeck that has the following declaration:
public class CardDeck {
private PlayingCard[] deck;
public static final int DECK_SIZE = 52;
//number of cards still in the deck:
private int numCardsLeft;
public CardDeck(){ ? }
private void removeCard(int index){ ? }
public void shuffle(){ ? }
public void wholeDeck(){ ? }
public PlayingCard topCard(){ ? }
public PlayingCard anyCard() { ? }
}
In your implementation, you must follow these guidelines:
1. Constructor of the class must properly initialize the CardDeck object: create the array object with number of "compartments" equal to DECK_SIZE and assign it to the field deck ; then create all 52 cards in such a way that there are no duplicate cards in the deck. You must use Java loop(s) to create the above PlayingCard objects. In addition, the constructor must assign the value DECK_SIZE to the field numCardsLeft.
2. Method removeCard(int index) must first check that the index is between 0 and the value of numCardsLeft-1. If it is true, then the method must
? shift all the cards in the deck array starting with index+1 and up to
numCardsLeft-1 position left by one "compartment"
? set the last value in the deck to null, like so:
deck[numCardsLeft-1] = null;
? decrement value of numCardsLeft by 1
3. Method shuffle()randomly re-arranges cards in the deck:
a) Declare a local variable temp of the type PlayingCard
B) Generate two random numbers i and j between 0 (inclusive) and DECK_SIZE
(exclusive) and swap the two cards stored at these index positions in the array:
temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
Repeat step B) at least 50 times, to get a good shuffle!
4. Method wholeDeck() must display descriptions of all the cards in the deck on screen. In order to do this, use an enhanced for loop to iterate through the deck array, and for each PlayingCard element of it call method describeCard() of class PlayingCard.
5. Method topCard()calls removeCard with 0 passed as the parameter value, and
returns a copy of PlayingCard object that was removed (that is, the card that used to be at index 0 in the array, before we removed it).
6. Method anyCard() removes a PlayingCard object stored at a random index in the
array: using an object of class java.util.Random, generate a random number between 0 and numCardsLeft-1, and pass this value as the parameter to the method
removeCard. Method anyCard must return a copy of the of PlayingCard object that
was removed.
Part 5: Implement class CardDeckTest that contains only the method
public static void main (String[] args) which does the following:
? create an object of type CardDeck
? call the method wholeDeck()
? call the method shuffle()
? call the method wholeDeck() again
? call the method topCard(), store its result in a variable, and then use this variable to call method displayCard()of class PlayingCard
? call the method anyCard(), store its result in a variable, and then use this variable to call method displayCard()of class PlayingCard
demo programs:
use proper indentations
|