?
Solved

Java Exercise-Cant find class

Posted on 2008-10-08
9
Medium Priority
?
341 Views
Last Modified: 2012-05-05
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;
}
0
Comment
Question by:ca1358
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22675439
How are you trying to run this?  There is no static main method, so can't execute directly.  You will have to instantiate from another object or create a main method.

Hope that helps, please post back if you need more assistance after giving that a try.

Regards,
Kevin
0
 

Author Comment

by:ca1358
ID: 22675476
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\classes
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\LoadedDie\src\loadeddie\LoadedDie.java:19: ';' expected
         If (randNum < chanceForSix){            
C:\Documents and Settings\Angela\My Documents\NetBeansProjects\LoadedDie\src\loadeddie\LoadedDie.java:21: 'else' without 'if'
        else {                      
2 errors
BUILD FAILED (total time: 0 seconds)

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22675793
Well, java is case sensitive, so If is not equivalent to if.  
Change this: If (randNum < chanceForSix)
To this: if (randNum < chanceForSix)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ca1358
ID: 22675796
Can anybody explain what I am missing?
0
 

Author Comment

by:ca1358
ID: 22675808
That fix the compile errors
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Angela\My Documents\NetBeansProjects\LoadedDie\build\classes
compile-single:
BUILD SUCCESSFUL (total time: 0 seconds)

Can you explain what "<No main classes found>" means?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22675827
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.
0
 

Author Comment

by:ca1358
ID: 22675829
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));

    }
}
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22675847
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.
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22675861
Yes, you now have a Player object.

Now that player object needs to know about your Die object to roll it.  Instead of instantiating "Random myDie = new Random();" try instantiating your class LoadedDie then call your roll method.

Hopefully that helps.

And hopefully being clear enough.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question