I'm new to doing Java and i was wondering if anyone would happen to know why this return type error is occurring.

this is the following error
C:\Users\..\Desktop\Connect4Model.invalid method declaration; return type required
public reset(int numCols, int numRows)

public class Connect4Model
{
	Connect4Column [] columns; // an array of columns
	int NUM_COLUMNS; // how many columns we have in the game
	int NUM_ROWS;    // how many rows we have in the game
	int playerToGoNext = Connect4Column.RED_COUNTER; //can be red or yellow
	int autoplay;

//	public Connect4Model(int numCols, int numRows)
	//{
	//	NUM_COLUMNS = numCols;
	//	NUM_ROWS = numRows;
//
	//	columns = new Connect4Column[NUM_COLUMNS];
	//	for (int i=0; i < NUM_COLUMNS; i++) {
	//		columns[i] = new Connect4Column(NUM_ROWS);
	//	}
	//}

	int getNumCols() // simply return the number of columns
	{
		return NUM_COLUMNS;
	}

	int getNumRows() // simply return the number of rows
	{
		return NUM_ROWS;
	}

	int getNextPlayer() // returns who gets to go next
	{
		return playerToGoNext;
	}

	public reset(int numCols, int numRows)
	{

				NUM_COLUMNS = numCols;
				NUM_ROWS = numRows;

				columns = new Connect4Column[NUM_COLUMNS];
				for (int i=0; i < NUM_COLUMNS; i++) {
					columns[i] = new Connect4Column(NUM_ROWS);
				}
	}



	void reset()
	{
		for (int thisCol = 0; thisCol < NUM_COLUMNS; thisCol ++)
		{
			for (int thisRow = 0; thisRow < NUM_ROWS; thisRow ++)
			{
				columns[thisCol].numCounters = 0;
				columns[thisCol].counters[thisRow] = 0;
			}
		}
	}
	int getAutoplay()
	{
		return autoplay;
	}
	boolean setAutoplay(int selectedOption)
	{
		if(selectedOption >= 1 && selectedOption <= 3) // valid
		{
			autoplay = selectedOption;
			return true;

		}
		else
			return false;
	}

	int getSuggestedMove(int player_colour)
	{
		java.util.Random r = new java.util.Random();
		return r.nextInt(NUM_COLUMNS);
	}

	boolean go(int thisColumn) // try to put a counter at this col
	{
		if(thisColumn<0 || thisColumn>=NUM_COLUMNS)
			return false;

		//System.out.println("thisCol is " + thisColumn);
		if(columns[thisColumn].addCounter(playerToGoNext)==true)
		{
			if(playerToGoNext==Connect4Column.YELLOW_COUNTER)
				playerToGoNext=Connect4Column.RED_COUNTER;
			else
				playerToGoNext=Connect4Column.YELLOW_COUNTER;
			return true;
		}
		return false;
	}

	int getCounter(int thisColumn, int thisRow) //
	{
		if(thisColumn<0 || thisColumn>=NUM_COLUMNS)
			return 0;
		return columns[thisColumn].getCounter(thisRow);
	}
	int getNumCounters(int thisColumn) //
	{
		if(thisColumn<0 || thisColumn>=NUM_COLUMNS)
			return 0;
		return columns[thisColumn].getNumCounters();
	}


}

Since "reset" is not a constructor, you must define it as returning void if you do not want it to return anything.
It's referring to line 35 where you say "public reset(int numCols, int numRows)" which is not a valid method declaration. Your other method declaration of reset is perfectly fine, so get rid of the first one.

Edited 6 Years Ago by BestJewSinceJC: n/a

Since "reset" is not a constructor, you must define it as returning void if you do not want it to return anything.
It's referring to line 35 where you say "public reset(int numCols, int numRows)" which is not a valid method declaration. Your other method declaration of reset is perfectly fine, so get rid of the first one.

I understand fully what you said fully however what I'm trying to do is write a write a reset() method, in the Connect4Model class. Which can take two parameters, the number of columns and number of rows. The implementation is actually the contents of the Connect4Model constructor, so all that constructor code can be moved into this new method, and now all that the constructor has to do is call the reset() method. The model should now be reset when you press the button, and i was wondering what the best way is to go about that?

Edited 6 Years Ago by ku95: n/a

you need to make the rest into a static method, so you can call it Connet4Model.rest(numCols, numRows) in your constructor.
static void rest(int numCols, int numRows){...}

since your rest method require two int variable, you need two parametesr for your constructor.

public Connect4Model(int numCols, int numRows){
Connet4Model.rest(numCols, numRows);
}

Edited 6 Years Ago by wildplace: n/a

This article has been dead for over six months. Start a new discussion instead.