Bugs item #1934640, was opened at 2008-04-04 10:01
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1934640&group_id=44253
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: a bug for compiling
Initial Comment:
public class ExtendedBoard extends Board
{
private final String EMPTY = "";
// An array to store the colour of the peg at each board position. If a peg
// is not present on the board at a particular position, the corresponding
// element of the array is the empty string "".
private String[][] colorOfPegAt;
// Construct and initialize a 2-D ExtendedBoard object by calling a superclass constructor,
// allocating memory for colorOfPegAt, and setting all its entries to "".
public ExtendedBoard( int rows, int cols )
{
// ADD CODE HERE
super(rows , cols);
}
// Construct and initialize a 1-D ExtendedBoad object, which is just a 1 x cols 2-D ExtendedBoard.
public ExtendedBoard( int cols )
{
// ADD CODE HERE
super(cols);
}
// Pre: row and col are valid Board positions and color is a valid colour.
// Post: a peg of the indicated color has been added to the board at the
// specified position, and its color has been recorded in colorOfPegAt.
public void putPeg( String color, int row, int col )
{
// ADD CODE HERE
this.colorOfPegAt[row][col] = color;
}
// Pre: col is a valid Board position and color is a valid color.
// Post: a peg of the indicated color has been added to the board at the
// specified position, and its color has been recorded in colorOfPegAt.
public void putPeg( String color, int col )
{
// ADD CODE HERE
this.colorOfPegAt[0][col] = color;
}
// Pre: row and col are valid board positions.
// Post: there is no peg at the indicated position and the corresponding element of colorOfPegAt is "".
public void removePeg( int row, int col )
{
// ADD CODE HERE
super.removePeg(row, col);
colorOfPegAt[row][col] = this.EMPTY;
}
// Pre: col is a valid board position.
// Post: there is no peg at the indicated position and the corresponding element of colorOfPegAt is "".
public void removePeg( int col )
{
// ADD CODE HERE
super.removePeg(col);
colorOfPegAt[0][col] = this.EMPTY;
}
// Pre: row and col are valid board positions.
// Post: returns the color of the peg at the specified position, or "" if there is none.
public String getPeg( int row, int col )
{
// ADD CODE HERE
if (colorOfPegAt[row][col]!=this.EMPTY)
{
return colorOfPegAt[row][col];
}else
{
System.out.println("There is none.");
return "";
}
}
// Pre: rcol is a valid board position.
// Post: returns the color of the peg at the specified position, or "" if there is none.
public String getPeg( int col )
{
// ADD CODE HERE
if (colorOfPegAt[0][col]!=this.EMPTY)
{
return colorOfPegAt[0][col];
}else
{
System.out.println("There is none.");
return "";
}
}
// A simple test.
public static void main( String[] args )
{
ExtendedBoard myBoard = new ExtendedBoard( 5, 5 );
myBoard.putPeg( "green", 0, 0 );
myBoard.putPeg( myBoard.getPeg(0,0), 4, 4 );
myBoard.putPeg( "yellow", 0, 4 );
myBoard.putPeg( myBoard.getPeg(0,4), 4, 0 );
}
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=438935&aid=1934640&group_id=44253
|