[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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
1
Medium Priority
?
173 Views
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

0
Comment
Question by:calbanese13
1 Comment
 
LVL 17

Accepted Solution

by:
Thomas4019 earned 2000 total points
ID: 24153702
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.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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