Hello, I am having trouble with a few methods in one of my classes (Deck)
I have 2 classes; Deck & Cards
Two methods in Deck that I am unsure how to create is;
"add" which is suppose to (accepts a card as its parameter and adds it to the bottom). I am using an array and I am not sure how to figure out the bottom of the array after x amount of cards have been won(collected) because the player
"getSize" - Since I am using an array I either need to make a loop to count each individual element or create a counter. A counter would be more efficient in this scenario because it would locate the bottom of the array to help out with "add" method.
Thank you for your help!
Here is my whole class Deck
import java.util.Random; /* Deck.java Class * Holds number of cards and maintains order */ public class Deck { private final int TOTALCARDS = 52; //total amount of cards placed in the array private Card[] deck; // array to hold the cards public final int topdeck = 0; // top of the deck //makes a deck of cards with one of each card public Deck(){ deck = new Card[52]; int count=1; for (int s = 1; s<=4; s++) { for(int v = 2; v<=14; v++) { deck[count] = new Card(v,s); count++; } } } //Shuffling of the array public Shuffle() { Random generator = new Random(); //Shuffles deck 500 times for (int i = 0; i < 500; i++) { int RandomCard = generator.nextInt(i); Card temp; temp = deck[i]; deck[i] = deck[RandomCard]; deck[RandomCard] = temp; } } //pre-conditions: Deck of at least 1 card //post-conditions: Removes the first card from the top of the deck and returns it public Draw() { int temp = topdeck; topdeck++; return deck[temp]; } // public Add(Card) // { // // } // public getSize() // { // return topdeck; // } // }