Since I'm a Java Novice, I need some help writing a program (not sure why I come up as an expert; I'm not)

Posted on 2009-04-15
Last Modified: 2013-11-23
I have to write a program that has a class dice that produces a random integer with a value of 1 to 6 (inclusive).  I need to write another class throw that gets two random numbers from class dice and adds them together.  Then I have to write a class count that counts the number of times each total appears and stores the result in an array.  Finally, I must write a class output that displays the results, showing the total (2 through 12) and the number of times it appeared in 1000 throws.

My initial code for the first part of my problem follows.  Is this right?  Do I import java.lang?  

Public class Dice {  

     private  RandomGenerator  rgen = RandomGenerator.getInstance();

     int die = rgen.nextInt(1, 6)

     println(Rolling dice:  + die + );

            return total;


Open in new window

Question by:calbanese13
    1 Comment
    LVL 17

    Accepted Solution

    In java you never need to import "java.lang.*" That is imported automatically.

    Java is a case-sensitive language, the keyword "public" should be all lower case whenever you use it.

    The class "RandomGenerator" is not part of the Standard Java programming language. Is it part of an extension you are using. I dont know if that code is right without knowing where that class is from.

    In java, there are no globals, everything is in a class. You cannot just say println(). You need to use System.out.println("Some String"). Also, whenever you have a String literal in java, it must be enclosed in quotes. Your line 6 should look something like System.out.println("Rolling dice: " + die);

    As for the rest of the project. I can only help you with specific problems or questions.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    hash value 2 29
    Connect to IP Camera using Java 4 61
    nestparen challenge 4 37
    strCopies  challenge 17 60
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This video teaches viewers about errors in exception handling.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now