ca1358
asked on
Java Exercise-Cant find class
I am doing this exercise in Java and when I try to run it, it says no Class found and I have 2 errors. Any help would greatly be appreciated.
package loadeddie;
import java.util.Random;
public class LoadedDie{
public LoadedDie(int pctChance)
{
chanceForSix = pctChance;
Random generator = new Random();
}
public int rollDie()
{
int chanceForOthers;
int randNum;
chanceForOthers = (100 - chanceForSix)/5;
randNum = generator.nextInt(100);
If (randNum < chanceForSix){
return 6;}
else {
return(randNum - chanceForSix)/ chanceForOthers;}
}
private int chanceForSix;
private Random generator;
}
package loadeddie;
import java.util.Random;
public class LoadedDie{
public LoadedDie(int pctChance)
{
chanceForSix = pctChance;
Random generator = new Random();
}
public int rollDie()
{
int chanceForOthers;
int randNum;
chanceForOthers = (100 - chanceForSix)/5;
randNum = generator.nextInt(100);
If (randNum < chanceForSix){
return 6;}
else {
return(randNum - chanceForSix)/ chanceForOthers;}
}
private int chanceForSix;
private Random generator;
}
ASKER
Sorry, I am Lost.
Running in NetBeans IDE 6.1.
This is what the result at the bottom says:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects \LoadedDie \build\cla sses
C:\Documents and Settings\Angela\My Documents\NetBeansProjects \LoadedDie \src\loade ddie\Loade dDie.java: 19: ';' expected
If (randNum < chanceForSix){
C:\Documents and Settings\Angela\My Documents\NetBeansProjects \LoadedDie \src\loade ddie\Loade dDie.java: 21: 'else' without 'if'
else {
2 errors
BUILD FAILED (total time: 0 seconds)
Running in NetBeans IDE 6.1.
This is what the result at the bottom says:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects
C:\Documents and Settings\Angela\My Documents\NetBeansProjects
If (randNum < chanceForSix){
C:\Documents and Settings\Angela\My Documents\NetBeansProjects
else {
2 errors
BUILD FAILED (total time: 0 seconds)
Well, java is case sensitive, so If is not equivalent to if.
Change this: If (randNum < chanceForSix)
To this: if (randNum < chanceForSix)
Change this: If (randNum < chanceForSix)
To this: if (randNum < chanceForSix)
ASKER
Can anybody explain what I am missing?
ASKER
That fix the compile errors
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects \LoadedDie \build\cla sses
compile-single:
BUILD SUCCESSFUL (total time: 0 seconds)
Can you explain what "<No main classes found>" means?
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects
compile-single:
BUILD SUCCESSFUL (total time: 0 seconds)
Can you explain what "<No main classes found>" means?
See my first comment as I thought that was were you were at with errors. :) As the error suggests you don't have a main method.
If you need more / deeper explaination you can refer to http://java.sun.com/docs/books/tutorial/ or post back after trying to implement based on my feedback.
If you need more / deeper explaination you can refer to http://java.sun.com/docs/books/tutorial/ or post back after trying to implement based on my feedback.
ASKER
I found this piece of code, Can I change this to fit my code?
package loadeddie;
import java.util.Random;
public class LoadedDieTester {
public static void main(String[] args)
{
Random myDie = new Random ();
System.out.println("The Result of the toss is " + (myDie.nextInt(6)+1));
}
}
package loadeddie;
import java.util.Random;
public class LoadedDieTester {
public static void main(String[] args)
{
Random myDie = new Random ();
System.out.println("The Result of the toss is " + (myDie.nextInt(6)+1));
}
}
Think of this in object oriented terms. You have created a dice object that is now sitting on the table. It will never roll unless you have a Player object or something that rolls it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope that helps, please post back if you need more assistance after giving that a try.
Regards,
Kevin