thank alot for the help...........but some of the method were incorrect and were missing but i manage to fix some.
i'm jux wonder if u could help out on the remove method... and the display method and the group class.
which i was very confuse.
task.
method
remove(int row, int col) – removes the bubble at row row and column col. To remove a bubble, simply move the bubbles behind the bubble we want to remove at row row forward (towards 0) by one position. Then reduce the position row of length by 1. If a row has no bubble left, length of that row will be 0, however, that row will still remain in grid (the GUI class will skip that row when it sees the length is 0).
display() – print (the color of) bubbles in every row with their row numbers, excluding empty rows, to standard output. An example is shown below.
0: 2 0 0 4 2
1: 2 1 3 2 3 0 4
2: 2 0 4 1 1 2 0
3: 4 4 0 2 3 4
4: 1 1 0 1 2 4
5: 2 0 0 1
6: 1 0
7: 0 3 1 0 3
8: 4 2 1 1 2 0 3
my display method;
CODE
public void display()
{
System.out.print(" ");
for (int k =0; k < board.length; k++)
{
System.out.print(k + " ");
}
System.out.println();
for (int i = 0; i < board.length; i++)
{
System.out.print(i + ": ");
for (int j = 0; j < board[i].length; j++)
{
System.out.print(board[i][j] + " ");
}
System.out.println();
}
}
The Group class
instruction
The Group class
This class represents a group of connected same colored bubbles. When user clicks on a bubble, a Group object is created containing that bubble and connected bubbles of the same color. This class has the following private fields:
grid – of type Grid. The grid object for this game.
nRows – is an int, which stores the number of rows in grid.
nCols – is an int, which stores the number of columns in grid.
seen – is a 2 dimensional boolean array. This 2D array indicates which bubbles are in this group. If row 1, column 3 in this array is set to true, then the bubble at that position is in this group.
color – is an int, which is the color of this group.
size – is an int, which is the number of bubbles in this group.
Group has one constructor. This constructor takes 3 parameters. The first parameter is a grid object, which will be assigned to the grid field. The second and third parameters are of type int, together these two values define the starting position, row and column, in grid to search for the bubbles in this group. Furthermore, the color of the bubble in that position is the color that is assigned to the color field. The fields nRows and nCols will be assigned the number of rows and columns of grid. A new 2 dimensional boolean array, with the same number of row and column as grid, will be created and assigned to the field seen. All elements in seen will then be initialised to false. The flood method will be called, and return result assigned to the field size.
Group has the following instance methods:
size() – which returns the size of this group.score() – which returns an int value which is the score for this group. The scored is calculated by: size * (size -1).
contains(int row, int col) – given a position in grid defined by row and col, this method returns true if the position is in this group, otherwise return false.
flood(int row, int col) – determines the bubbles in this group given the starting position row, col. To indicate the bubbles in this group, the positions of the bubbles in this group will be set to true in seen. This method returns the number of bubbles in this group. As this method is only used within this class, the access modifier for this method is private.
highlight in red is what i started.
my code for group class;
CODE
public class Group
{
private grid;
private int nRows;
private int nCols;
private seen [][];
private int color;
private int size;
}
public Group ( grid, int nRows, int nCols)
{
grid=grid;
color=color;
grid = new int [nRows][nCols]
=
public int size() {
{
public int score(){
{
This post has been edited by kamiz: 24 Sep, 2008 - 05:03 AM