I am working on a command line type of program that would allow you to play solitaire. I currently have class Deck and class Card. In class Deck i have an ArrayList and two methods - one that creates a deck and one that shuffles it. I need to create a method that deals a card - meaning a method that would pick a random element from an ArrayList and it is gonna erase it from the ArrayList. When a card is dealt it is not in the ArrayList anymore, i believe. Here is the code in my Deck class:
public class Deck {
private ArrayList deck = new ArrayList < Card > ();
private Random randomGenerator;
}
public Deck() {
for (Suit s: Suit.values())
for (Numbers n: Numbers.values()) {
Card c1 = new Card(n, s);
deck.add(c1);
System.out.println(deck);
}
}
private void printAll() {}
public void shuffle() {
Collections.shuffle(deck);
}
I'm really having a hard time with creating a method that would erase the dealt element, what i have done so far is pretty much based on the answers of this problem but it is not quite what i need. Retrieving a random item from ArrayList
public Card deal(deck) {
Random rand = new Random();
Card dealtCard = rand.deck();
return dealtCard;
}
Could anyone provide any guidance for me on this method? Please and thank you