5 Replies - 384 Views - Last Post: 03 March 2012 - 10:00 PM Rate Topic: -----

#1 ertopp  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 74
  • Joined: 27-February 11

Getting A LOT of errors..

Posted 03 March 2012 - 09:43 PM

So I have this assignment that I have been working on but my professor just went on leave and I am not getting much help elsewhere. Can anyone help with these errors?

This is the code I have:
public class CoinPitch {

		double gameboard[][];
		String prizes[];
		int coinTosses[][];
		int prizeCount[];
		loadBoard();
		displayBoard(double gameboard);
		tossCoins(int coinTosses);
		determineWinners(int prizeCount);
		displayWinners();

public CoinPitch()
	{
		gameboard = new double[5][5];
		prizes = new String[5];
		coinTosses = new int[10][2];
		prizeCount = new int[5];
	}
private void loadBoard()
{
	for (int i = 0; i < prizes.length; i++)
	{
		{int n = 1;
		boolean found = false;
		while (!found && n <= 3)
		}

	}
}
private void displayBoard(int[][]gameboard)
	{
		for (int row = 0; row < 5; row++)
		{
			for (int col = 0; col < 5; col++)
				System.out.println(gameboard[row][col]);
		}
	}
private void tossCoins(int[][] coinTosses)
{
		int r;
		int minimum = 0;
		int maximum = 4;

		for (r = 0; r < coinTosses; r++)
		{	coinTosses[r][0] = (int)(Math.random() * (maximum - minimum));
			coinTosses[r][1] = (int)(Math.random()*  (maximum - minimum));}

}
private void determineWinners(int prizeCount)
	{
		for (int n = 0; n < prizeCount; n++){
			for (int r = 0; r < coinTosses; r++)
		}

	}
private void displayWinners(int i)
	{
		for (i = 0; i < prizeCount; i++)
	}

}



These are the PILE of errors I am getting:
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:16: invalid method declaration; return type required
loadBoard();
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:17: invalid method declaration; return type required
displayBoard(double gameboard);
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:18: invalid method declaration; return type required
tossCoins(int coinTosses);
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:19: invalid method declaration; return type required
determineWinners(int prizeCount);
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:20: invalid method declaration; return type required
displayWinners();
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:36: illegal start of expression
}
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:40: illegal start of expression
private void displayBoard(int[][]gameboard)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:40: illegal start of expression
private void displayBoard(int[][]gameboard)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:40: ';' expected
private void displayBoard(int[][]gameboard)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:40: ';' expected
private void displayBoard(int[][]gameboard)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:48: illegal start of expression
private void tossCoins(int[][] coinTosses)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:48: illegal start of expression
private void tossCoins(int[][] coinTosses)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:48: ';' expected
private void tossCoins(int[][] coinTosses)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:48: ';' expected
private void tossCoins(int[][] coinTosses)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:59: illegal start of expression
private void determineWinners(int prizeCount)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:59: illegal start of expression
private void determineWinners(int prizeCount)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:59: ';' expected
private void determineWinners(int prizeCount)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:59: ';' expected
private void determineWinners(int prizeCount)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:63: illegal start of expression
}
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:66: illegal start of expression
private void displayWinners(int i)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:66: illegal start of expression
private void displayWinners(int i)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:66: ';' expected
private void displayWinners(int i)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:66: ';' expected
private void displayWinners(int i)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:69: illegal start of expression
}
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:74: reached end of file while parsing
}
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:22: CoinPitch() is already defined in CoinPitch
public CoinPitch()
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:54: operator < cannot be applied to int,int[][]
for (r = 0; r < coinTosses; r++)
^
C:\Users\Erin\Desktop\CIT 130\CoinPitch.java:62: operator < cannot be applied to int,int[][]
for (int r = 0; r < coinTosses; r++)


I am so lost :(

Is This A Good Question/Topic? 0
  • +

Replies To: Getting A LOT of errors..

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7958
  • View blog
  • Posts: 13,561
  • Joined: 19-March 11

Re: Getting A LOT of errors..

Posted 03 March 2012 - 09:50 PM

loadBoard();
      displayBoard(double gameboard);
      tossCoins(int coinTosses);
      determineWinners(int prizeCount);
      displayWinners()



It looks like you're trying to call these methods. Since you're not in a method here, you can't call a method at this point, so the compiler thinks you're trying to declare the method, and this isn't a valid method declaration.

      while (!found && n <= 3)
      }



What do you want to do while not found and n is le 3?

         for (int r = 0; r < coinTosses; r++)
      }


Same issue here.

private void displayWinners(int i)
   {
      for (i = 0; i < prizeCount; i++)
   }



And here.



Those are the first couple. Solve those and there will be some more...

This post has been edited by jon.kiparsky: 03 March 2012 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 ertopp  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 74
  • Joined: 27-February 11

Re: Getting A LOT of errors..

Posted 03 March 2012 - 09:52 PM

This is what he says to do for the second part you mentioned but I can't figure it out:

2.2.2.1. row = random number in the range 0 through 4 for a row index in 5 x 5 table
2.2.2.2. col = random number in the range 0 through 4 for a column index in 5 x 5 table
2.2.2.3. if table[row][col] is empty, set table[row][col] = prizes[i] and set found = true
Was This Post Helpful? 0
  • +
  • -

#4 btanne6  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 46
  • Joined: 24-November 11

Re: Getting A LOT of errors..

Posted 03 March 2012 - 09:54 PM

Don't be overwhelmed by a lot of errors, most of the time it's a few simple things that will clear up the majority of them. Now on your code a lot of errors are jumping out. You forgot a lot of semicolons at the end of statements. You also declare variables in the method calls,
tossCoins(int coinTosses);

coinTosses has to have a value to be able to pass it to the method.
Another is you need to understand parameters and method return types.
displayBoard(double gameboard);

then
private void displayBoard(int[][]gameboard)

you're trying to pass displayBoard an undefined double when it accepts a multidimensional array int[][]. You have to accept the same data type you pass. Look at some tutorials for methods in java to help understand better.
Was This Post Helpful? 0
  • +
  • -

#5 ertopp  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 74
  • Joined: 27-February 11

Re: Getting A LOT of errors..

Posted 03 March 2012 - 09:55 PM

Any suggestions for why I am getting the "illegal start of expression" errors? I can't figure those out!
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7958
  • View blog
  • Posts: 13,561
  • Joined: 19-March 11

Re: Getting A LOT of errors..

Posted 03 March 2012 - 10:00 PM

Well, you'll have to put something in there if you want to expose the next round of errors.

You can put an empty statement block for now, if you want:

while (!found && n <= 3)
  {
  }




It'll spin forever if the condition is true, so don't bother running it, but it'll at least be a step closer to compiling. It looks like you need to set a variable called row to a random number in the range [0..4] - use either java.util.Random or Math.random() to accomplish this. See the linked documentation, you should be able to make a good try at it.

For testing purposes, you could assume that 4 is random enough for now, and then move on to 2.2.2.3

This post has been edited by jon.kiparsky: 03 March 2012 - 10:01 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1