Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For these errors, in your <code>RPSMain</code> class, you're trying to access variables from your other classes. Your code here...</p> <pre><code> for (int i = 0; i &lt; rounds; i++){ player.makeThrow(); gameObject.makeThrow(); gameObject.announceWinner (compThrow, getPThrow); } </code></pre> <p>Should actually be this...</p> <pre><code> for (int i = 0; i &lt; rounds; i++){ int playerThrow = player.makeThrow(); int compThrow = gameObject.makeCompThrow(); gameObject.announceWinner (compThrow, playerThrow ); } </code></pre> <p>Note that when we call a method like <code>makeThrow()</code>, we capture the variable and call it <code>playerThrow</code>. Now we can use this variable in the <code>announceWinner()</code> method. The same for the <code>compThrow</code> variable.</p> <p>You are doing the same thing in your <code>RPSGame.bigWinner(winner, rounds);</code> line - its complaining that <code>winner</code> doesn't exist. This is true - <code>winner</code> is not a variable in <code>RPSMain</code>, its only a variable in <code>RPSGame</code> - you can't share the variables between different classes like this. </p> <p>Your <code>gameObject.announceWinner()</code> method returns an <code>int</code> that represents the actual winner. If you want to use this returned value, you need to capture it into a variable. Currently you have code like this in <code>RPGMain</code>...</p> <pre><code>for (int i = 0; i &lt; rounds; i++){ int playerThrow = player.makeThrow(); int compThrow = gameObject.makeCompThrow(); gameObject.announceWinner (compThrow, playerThrow ); } System.out.print (gameObject.bigWinner(winner, rounds)); </code></pre> <p>If you want to keep the <code>int</code> returned from the <code>announceWinner()</code> method, you have to capture it by making the following adjustment...</p> <pre><code>for (int i = 0; i &lt; rounds; i++){ int playerThrow = player.makeThrow(); int compThrow = gameObject.makeCompThrow(); int winner = gameObject.announceWinner (compThrow, playerThrow ); System.out.print (gameObject.bigWinner(winner, rounds)); } </code></pre> <p>This now says that the value returned from <code>gameObject.announceWinner()</code> will be stored in a local variable called <code>winner</code> in the <code>RPGMain</code> class. Now When it tries to use the <code>winner</code> variable in the <code>gameObject.bigWinner()</code> method of the next line, it knows about the value.</p> <p>To fix your <code>non-static method bigWinner(int,int) cannot be referenced from a static context</code> error, you need to change the following line...</p> <pre><code>public int bigWinner (int winner, int rounds){ </code></pre> <p>to have the word <code>static</code> in it, like this...</p> <pre><code>public static int bigWinner (int winner, int rounds){ </code></pre> <p>Or, better yet, remove the word <code>static</code> from everywhere in your code. If you're new to Java, trying to use <code>static</code> variables and methods will just make things more complicated then they really need to be, and I can't see any reason why you'd need them to be <code>static</code> in your program.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload