Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: need some help with an 2-d array project

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need some help with an 2-d array project

    This has to do with the game called chomp and it plays like this Java applet. The Chomp game
    I need help finishing this code with 2-d arrays

    // Implements a 2-D array of characters
     
    public class CharMatrix
    {
      // Fields:
      private int x;
      private int y;
     
      // Constructor: creates a grid with dimensions rows, cols,
      // and fills it with spaces
      public CharMatrix(int rows, int cols)
      {
      x = rows;
      y = cols;
      char[] array = new char[x][y];  
      }
     
      // Constructor: creates a grid with dimensions rows , cols ,
      // and fills it with the fill  character
      public CharMatrix(int rows, int cols, char fill)
      {
      x = rows;
      y = cols;
      char[] array = new char[x][y];  
        for(int i = 0; i < x; i++)
          for(int j = 0; j < y; j++)
            array[ i ][ j ] = fill;
      }
     
      // Returns the number of rows in grid
      public int numRows()
      {
        return x;
      }
     
      // Returns the number of columns in grid
      public int numCols()
      {
        return y;
      }
     
      // Returns the character at row, col location
      public char charAt(int row, int col)
      {
        return array[x][y];
      }
     
      // Sets the character at row, col location to ch
      public void setCharAt(int row, int col, char ch)
      {
        array[x][y] = ch;
      }
     
      // Returns true if the character at row, col is a space,
      // false otherwise
      public boolean isEmpty(int row, int col)
      {
        int counter = 0;  
        for(int i = 0; i < x; i++)
          for(int j = 0; j < y; j++)
        if (array[i][j].equals('0'))
    	counter ++;
        if(counter==x*y)	
    	return true;
        else return false;
      }
     
      // Fills the given rectangle with fill  characters.
      // row0, col0 is the upper left corner and row1, col1 is the
      // lower right corner of the rectangle.
      public void fillRect(int row0, int col0, int row1, int col1, char fill)
      {
        ...
      }
     
      // Fills the given rectangle with SPACE characters.
      // row0, col0 is the upper left corner and row1, col1 is the
      // lower right corner of the rectangle.
      public void clearRect(int row0, int col0, int row1, int col1)
      {
        ...
      }
     
      // Returns the count of all non-space characters in row 
      public int countInRow(int row)
      {
        ...
      }
     
      // Returns the count of all non-space characters in col 
      public int countInCol(int col)
      {
        ...
      }
    }
    Last edited by helloworld922; April 8th, 2011 at 12:07 AM.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: need some help with an 2-d array project

    Do not dump your homework and expect someone to fix it for you. Ask a specific question and get a specific answer.

Similar Threads

  1. Char array to a String array with hex
    By fortune2k in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 20th, 2014, 01:01 PM
  2. prininting out a 4x4 array according to an order by a 1d array
    By fortune2k in forum Collections and Generics
    Replies: 7
    Last Post: November 25th, 2010, 12:54 PM
  3. 2d (4x4) array insdie a 1d array. (Block cipher)
    By fortune2k in forum Collections and Generics
    Replies: 13
    Last Post: November 23rd, 2010, 05:29 PM
  4. Can anyone help me on my project?
    By alesana514 in forum Paid Java Projects
    Replies: 1
    Last Post: December 16th, 2009, 09:24 AM
  5. Need a project
    By helloworld922 in forum Project Collaboration
    Replies: 6
    Last Post: July 31st, 2009, 08:30 AM