Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reference a variable in main method from a static class? (java)
    text
    copied!<p>For my program I have a static class which uses a Boolean statement. I would like to use this variable in my main in the instance of the user winning or losing the game. </p> <p>However if I try to reference the variable it says it can not be found. </p> <p>Here is a fraction of my code</p> <pre><code> boolean playerWin; Dice.playerWin = false; </code></pre> <p>is there any reason why the symbol can not be found?</p> <p>Thanks.</p> <p>EDIT:</p> <pre><code> class Dice { static NumberFormat fmt = NumberFormat.getCurrencyInstance(); public static String playRound(double playerBet) { boolean playerWin; double amountWon = 0; if(playerWin = false) { Wallet.playerBalance -= playerBet; amountWon = 0; return fmt.format(amountWon); } else { Wallet.playerBalance *= 2; amountWon = 1d/2d * Wallet.playerBalance; return fmt.format(amountWon); } } </code></pre> <p>and in the main class</p> <pre><code> public class Game { public static void main(String[] args) { String playerName; int playerBet; Dice die = new Dice(); System.out.print("How much would you like to bet? "); while(playerBet != -1 &amp;&amp; playerBet &gt; 0) { playerDie.roll(); playerDie2.roll(); computerDie.roll(); computerDie2.roll(); if(computerDie.equals(computerDie2)); { System.out.print("Sorry you lost"); Dice.playerWin = false; } System.out.println(); System.out.print("How much would you like to bet on this round? "); playerBet = in.nextInt(); </code></pre> <p>The variable is in a static class and it is being used in the main method, what am I doing wrong? </p> <p>Hopefully this extra bit helps.</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