this is nothing complicated I just need to know what I am incorrect on. I was this program to display the dice and the roll numbers. after that I want it to add them and if they roll over 15 its a win, if not its a loss. This program is just a small exercise from a book we are using in class if anyone is wondering what this is. I am receiving illegal start of expressions and reached end while parsing.
public class BradySkuza36
{
public static void main( String[] args )
{
int roll1, roll2, roll3, roll4, roll5;
roll1 = 1 + (int)(Math.random()*6);
roll2 = 1 + (int)(Math.random()*6);
roll3 = 1 + (int)(Math.random()*6);
roll4 = 1 + (int)(Math.random()*6);
roll5 = 1 + (int)(Math.random()*6);
System.out.println("\nYou rolled: " + roll1 + " " + roll2 + " " + roll3 + " " + roll4 + " " + roll5);
showDice(roll1);
showDice(roll2);
showDice(roll3);
showDice(roll4);
showDice(roll5);
if(rollAdd >= 15)
{
System.out.println("You win!);
}
else
{
System.out.println("Sorry maybe next time.");
}
}
public static void showDice( int roll )
{
System.out.println("+ +");
if ( roll == 1 )
{
System.out.println("| |");
System.out.println("| o |");
System.out.println("| |");
}
else if ( roll == 2 )
{
System.out.println("|o |");
System.out.println("| |");
System.out.println("| o|");
}
else if ( roll == 3 )
{
System.out.println("|o |");
System.out.println("| o |");
System.out.println("| o|");
}
else if ( roll == 4 )
{
System.out.println("|o o|");
System.out.println("| |");
System.out.println("|o o|");
}
else if ( roll == 5 )
{
System.out.println("|o o|");
System.out.println("| o |");
System.out.println("|o o|");
}
else if ( roll == 6 )
{
System.out.println("|o o|");
System.out.println("|o o|");
System.out.println("|o o|");
}
System.out.println("+ +");
}
public static void rollAdd(int added)
{
added = roll1 + roll2 + roll3 + roll4 + roll5;
}
}
}
You have several small problems in your code.
First of all ,you have an extra }
at the end.Remove it. Secondly,call rolladd
using rolladd(roll1,roll2,roll3,roll4,roll5)
and change the method to
public static int rollAdd(int roll1,int roll2,int roll3,int roll4,int roll5)
{
int added = roll1 + roll2 + roll3 + roll4 + roll5;
return added;
}
Lastly,you are missing a "
in
System.out.println("You win!);