import java.util.ArrayList; import java.util.Scanner; public class Player { private ArrayList hand = new ArrayList<>(); public Player(Deck drawDeck) { for (int i = 0; i < 7; i++) { hand.add(drawDeck.deal()); } } public void add(Card c) { hand.add(c); } public Card getCardToPlay(Card upCard) { System.out.println("The up card is: " + upCard); System.out.println("Your hand is:"); for (int i = 0; i < hand.size(); i++) { System.out.println("\t" + (i+1) + ". " + hand.get(i)); } System.out.println("\t" + (hand.size()+1) + ". Skip and take a card"); Scanner in = new Scanner(System.in); System.out.print(": "); int choice = in.nextInt() - 1; // if they chose to bail, then return no card if (choice == hand.size()) { return null; } // make sure the choice was valid while (choice < 0 || choice >= hand.size() || !hand.get(choice).canBePlayed(upCard)) { System.out.print("Please enter a valid choice: "); choice = in.nextInt() - 1; if (choice == hand.size()) { return null; } } return hand.remove(choice); } }