I'm making a poker game in Java, and our teacher doesn't know Java that well so his instructions were written by a teacher's aid. I'm trying to make a Hand.java class to serve as a storage space for two character Strings that will act as cards (ie. "2h" = "2 of hearts").
His instructions are as follows:
- The Hand class is an object to be instantiated. It will represent a single hand within a game, and will mainly consist of an array of cards.
- Field: ArrayList cards Storage space for cards in hand List item
- Constructor: Hand(String[]) Initializes the cards field with an array of two-character abbreviations for cards.
- Method: void addCard(String) Adds the card represented by an abbreviation to the cards field
Here's what I have so far:
import java.util.*;
public class Hand {
public String[] array;
ArrayList<String> cards = new ArrayList<String>();
public Hand(String[] array) {
this.array = array;
}
public void addCard(String card) {
cards.add(card);
}
(further instructions) The final test should use the following sequence of commands in the main program. The program segment:
Hand h = new Hand("3c", "4s", "5d", "6h", "7h"); //program is upset with this line
h.printHand();
h.addCard("8d");
h.addCard("3d");
Should output:
Printing Hand: 5 cards – 3c 4s 5d 6h 7h
Adding Card: Eight of Diamonds (8d)
Adding Card: Three of Diamonds (3d)
Am I crazy, or do I actually need an array within the constructor of the Hand class? I don't understand his explanation of " Constructor: Initializes the cards field with an array of two-character abbreviations for cards" Any advice is much appreciated!