Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Dimensional Array problems

Status
Not open for further replies.

Maig

Technical User
Nov 14, 2003
32
CA
I'm trying to write a simple game program. I'm having trouble with two methods, one I want to return the number of rows in the array and one I want to return the number of columns in the array. I don't know how to do this. The array is a char array and I want the number of rows to be returned as an int. I just want it to count up the number of rows (or columns) in the array and return that number. The name of the array is grid.

public int numOfColumns()
{
return grid.length;
}

I know the above is wrong because it only counts the rows, not the columns.
 
Well, I figured that question out but now I have a new problem. I have a class called CoordinatePairs, which is a simple class that has rows and columns, accessor methods for each and set methods for each. What I need to do is use this CoordinatePairs class in my Array class to set a value in a specific location in the Array. I do not know how to code this...

public void setSpecificCoordinates(CoordinatePair coordsToSet, char valueToSet)
{
coordsToSet = grid[][]; // all wrong, I know
vauleToSet =
}

I really need some help with this one.
 
Code:
 char [][] grid;

public void setSpecificCoordinates(CoordinatePair coordsToSet, char valueToSet)
{
	grid[coordsToSet.getX ()][coordsToSet.getY ()] = vauleToSet;
} 

public void setSpecificCoordinates (int x, int y, char valueToSet)
{
	grid[x][y] = vauleToSet;
}

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top