What's wrong with my code for a dice game ? The method is not working?


#1

/** defining package */
package exercise07;
import java.util.Random;

/** class */
public class testfinal2 {

private static int numberOfGames = 10;
{

	/** Initializing all variables */
	int computerWins = 0, computerRoll = 0;
	int userWins = 0, userRoll = 0;
	int tiedGames = 0;


	/** Dice Roll Method */
	static int rollDie() {
	    Random randValue = new Random();
	    return randValue.nextInt(6) + 1;
	}


	for (int round = 0; round < numberOfGames; round++) {
	    computerRoll = rollDie();
	    userRoll = rollDie();

	    /** determines who won the game */
	    if (computerRoll == userRoll) {
	        tiedGames++;
	    } else {
	        if (computerRoll > userRoll) {
	            computerWins++;
	        } else {
	            userWins++;
	        }
	    }
	}
	
	
	/** displays the results */
	System.out.println("Computer...." + computerWins);
	System.out.println("User........" + userWins);
	System.out.println("Ties........" + tiedGames);
	
	
	/** Determines the Grand Winner */
	if (computerWins > userWins) {
	    System.out.println("You got beat by a computer!");
	} else {
	    if (computerWins < userWins) {
	        System.out.println("You beat the computer!");
	    } else {
	        System.out.println("The game has ended in a tie!");
	    }
	}
	
	
}

}


#2

At a quick glance, I would say that you need a return parameter. The interpreter would spit the dummy if you ran it in an actual java interpreter.

private static int numberOfGames = 10;

You're declaring a return type of int but you're not returning anything ! Go back to the beginning of what ever section tells you how to declare java code and read it again.
Also there is a lot more wrong with your declaration but you need to work it out for yourself. It's very basic stuff and if you get the answer handed to you how do you expect to learn ? Read up on some of the excellent java learning websites.

how are you running this ? If you're using the terminal, as I suspect CodeAcademy do, this declaration is not a valid java declaration.
To run a terminal program you need to declare your main class as

public static void ....etc etc.....

Remember this if you remember nothing else !