I am working on a solitaire game called Calculation.

The Foundation class provides the methods to manage and display the foundation of the Calculation game. Since the foundation contains four rows of cards, it is natural for the Foundation class to have a field that is an array of four "somethings", where each "something" represents a row of the foundation. So what I have to do is create a FoundationRow class to handle all the logic associated with one row of the foundation. Then later on when I create the Foundation class, it will have an array of four objects of the type FoundationRow.

Anyway, Im trying to write a constructor for class called FoundationRow.

**public FoundationRow(int startNumber, Deck deck)**

Parameters:

*startNumber*- the pip count for the first card in the row, which is also the difference in pip values for adjacent cards in this row. This must be a value in the range 1-4 inclusive.

*deck*- the deck of cards from which the first card whose pip count equals startNumber is extracted as the first card in the row. When the constructor returns, the number of cards in the deck will be one less than where it was called due to the removal of this card. It may be assumed that the gicen deck contains such a card.

The constructor should set up an array of 13 cards in which the first element is the first card in the given deck of the required pip number.

In the game calculation, a card's suit is irrelevant, only the pip count (1-13) is relevant. The game starts with a shuffled deck of cards from which an ace, two, three and four have been extracted. These four extracted cards form the start of four foundation rows. The goal of the game is to build up each foundation row from its start card through to a king. A card can only be added to a foundation row only in the first free position and only if its "pip value" differs from the card to its left by the pip value of the left-most card in the row.

Thus the first row takes cards A,2,3,4..., the second row takes 2,4,6,8,10,Q,A,3... , the third row takes 3,6,9,Q,2,5,8... and the fourth row takes 4,8,Q,3,7,J...

I am having trouble implementing the Constructor as I do not know how to write the code for the Constructors parameters.

Any suggestions?

Thanks

(Ive attached the outline of the FoundationRow class if it is of any help)

/** * A FoundationRow is a single row in a foundation. It has a start card, * which determines the step size in number of pips between cards in a row. */ public class FoundationRow { private Deck deck; /** *Constructor for objects of class FoundationRow that will not be *displayed graphically. When the constructor returns,the number of cards in the deck will be one less than when it was called due to the removal of *this card.It may be assumed that the given deck contains such a card. [email protected] startNumber the pip count for the first card in the row, which is also the difference in pip values for adjacent cards *in this row. This must be value in the range 1-4 inclusive. [email protected] deck the deck of cards from which the first card whose pip count equals startNumber is extracted as first card in the *row. */ public FoundationRow(int startNumber, Deck deck) { deck = this.deck; } /** *An array of 13 elements, each of which is either a Card or null. If the row contains n (1-13 inclusive) cards, *element 0...n-1 will be the cards, and elements n onwards will all be null. This is just a getter method for the *array of cards in this foundation row. [email protected] an array of 13 elements,with the first n being the cards in this row and the remaining 13-n being null, *when n is the number of cards currently in this row. */ public Card[] getCards() { return null; } /** * Add (or attempt to add) the given card to this row. Returns true if the add is successful,i.e.,the difference between * the number of pips on this card and the number of pips on the card currently at the end of the row is equal to the * number of pips on the card at the start of the row. If the parameter is null,the method returns false * @param card the card to be add to the row, if possible. * @return true if and only if the add succeeds. */ public boolean putCard(Card card) { return true; } /** * A string representation of the object. This is the string representations of each card in the row, separated by single space. * There are no spaces at the start or end of the row -- only between the individual cards. * @overrides toString in class java.lang.Object */ public String toString() { return ""; } }

This post has been edited by **Richard Goodwin**: 16 May 2006 - 06:38 AM