unreacheable statement error

I'm new to Java. honestly most of the time i have no idea what i'm doing. I'm suppose to do a prog. about dice throwing simulation. I'm getting the following errors that i do not understand:

DiceSimulation232.java:59: unreachable statement DiceSimulation232 DiceSimulation232 = new DiceSimulation232();

and

DiceSimulation232.java:91: missing return statement

}

^

below is my prog. any help will be appreciated.

import java.io.PrintStream.*;

import java.util.Scanner;

import java.io.*;

public class DiceSimulation232

{

static final int NUMBER_OF_ROLLS = 10000;

public static void main(String[] args)

{

double average;

System.out.println("Total On DiceAverage Number of Rolls");

System.out.println("---");

for ( int dice = 2; dice <= 12; dice++ )

{

average = getAverageRollCount( dice );

System.out.println(dice + " " + 10);

System.out.println("");

System.out.println(average);

}

}

static double getAverageRollCount( int roll )

{

int rollCountThisExperiment;

int rollTotal;

double averageRollCount;

rollTotal = 0;

for ( int i = 0; i < NUMBER_OF_ROLLS; i++ ) {

rollCountThisExperiment = rollFor( roll );

rollTotal += rollCountThisExperiment;

}

averageRollCount = ((double)rollTotal) / NUMBER_OF_ROLLS;

return averageRollCount;

}

static int rollFor( int N )

{

int die1, die2;

int roll;

int rollCt;

rollCt = 0;

boolean done = false;

do {

die1 = (int)(Math.random()*6) + 1;

die2 = (int)(Math.random()*6) + 1;

roll = die1 + die2;

rollCt++;

} while ( roll != N );

return rollCt;

DiceSimulation232 DiceSimulation232 = new DiceSimulation232();

System.out.println("Dice throwing simulation");

do

{

System.out.println("Options: (n)ew simulation, (a)dditional rolls," +

" (p)rint report, (q)uit");

System.out.print("Enter n, a, p, or q ==> ");

char choice;

Scanner keyboard = new Scanner(System.in);

choice = keyboard.next().charAt(0);

switch (choice)

{

case 'n': case 'N':

System.out.println("newSimulation");

break;

case 'a': case 'A':

System.out.println("additionalRolls");

break;

case 'p': case 'P':

System.out.println("printReport");

break;

case 'q': case 'Q':

done = true;

break;

default:

System.out.println("Invalid selection.");

} // end switch

} while (!done);

}

} // end DiceSumulation232

thanks

[2767 byte] By [Jlovea] at [2007-10-2 1:00:59]
# 1

First, try to use code tags - it makes reading this much easier.

But the most likely error I see is:

return rollCt;

DiceSimulation232 DiceSimulation232 = new DiceSimulation232();

System.out.println("Dice throwing simulation");

Once you say return the method will not continue to run. It stops there. Also, even though the compiler just told you that the rest of the body of the method will not execute it then told you that in case you fix it you must return something from the method. What did you want to return at the very end of the rollFor() method?

stdunbara at 2007-7-15 18:21:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

> > return rollCt;

>

> DiceSimulation232 DiceSimulation232 = new

> DiceSimulation232();

> System.out.println("Dice throwing simulation");

>

Like the guy said you have code after the return statement. That code is in fact unreachable because the method finishes when it hits the return.

try doing

DiceSimulation232 DiceSimulation232 = new

DiceSimulation232();

System.out.println("Dice throwing simulation");

return rollCt;

and ensure that you also assign a value to rollCT

before you return it.

javakicksassa at 2007-7-15 18:21:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...