Hey guys. Run into a small problem on a lab exercise. Supposed to use the method "dealACard()" inside of "dealAHand(int handSize)" Here's my actual instructions.
"6. The dealACard method returns the Card from the array of Card objects in position nextCard. See the diagram below that illustrates how this should work.
7. The dealAHand method has a loop that deals one Card (using the previous method) at a time until it has dealt handSize Cards. The String returned is a list of the Card objects in the hand – similar to the result of toString except that the String returned here contains only handSize lines."
I've attached my code, clearly I can't get the method "dealAHand(int handSize) to work, so I'm just leaving it blank. It does have to return on a String. Thanks for the help! The method I need help with, is the bottom one. Thanks!
import java.util.Random; /** * --------------------------------------------------------------------------- * File name: Deck.java<br/> * Project name: CardProject<br/> * --------------------------------------------------------------------------- * Creator's name and email: Austin Stanley, Stanleyar@Goldmail.etsu.edu<br/> * Course: CSCI1260-002<br/> * Creation Date: Feb 11, 2013<br/> * Date of Last Modification: Feb 11, 2013 * --------------------------------------------------------------------------- */ /** * Enter type purpose here<br> * * <hr> * Date created: Feb 11, 2013<br> * Date last modified: Feb 11, 2013<br> * <hr> * @author Austin Stanley */ public class Deck { private Card[] deck; private int nextCard; /** * Default Constructor <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> */ public Deck() { nextCard = 0; deck = new Card[52]; for(int n=0; n<52; n++) { deck[n] = new Card(n); } } /** * Copy Constructor <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> * @param deckIn */ public Deck(Deck deckIn) { deck = new Card[52]; for(int i = 0; i < deck.length; i++) deck[i] = deckIn.deck[i]; nextCard = 0; } /** * Enter method description here <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> * @return * @see java.lang.Object#toString() */ public String toString() { String result = ""; for(int n=0; n < deck.length; n++) { result += deck[n] + "\n"; } return result; } /** * Enter method description here <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> */ public void shuffle() { Random rgen = new Random(); for(int i=0; i<deck.length; i++) { int randomShuffle = rgen.nextInt(deck.length); Card temp = deck[i]; deck[i] = deck[randomShuffle]; deck[randomShuffle] = temp; } } /** * Enter method description here <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> * @return */ public Card dealACard() { int currentCard = nextCard; nextCard++; return deck[currentCard]; } /** * Enter method description here <br> * * <hr> * Date created: Feb 11, 2013 <br> * Date last modified: Feb 11, 2013 <br> * * <hr> * @param handSize * @return */ public String dealAHand (int handSize) { for(int i = 0; i < handSize; i++) return "Your hand is"; } }