*
The moose likes Beginning Java and the fly likes The MathQuiz file doesnt seem to run i dont know why Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The MathQuiz file doesnt seem to run i dont know why" Watch "The MathQuiz file doesnt seem to run i dont know why" New topic
Author

The MathQuiz file doesnt seem to run i dont know why

Tim Lai
Greenhorn

Joined: Dec 01, 2012
Posts: 2
could there be a problem with how i called the randomgenerator. thanks

-Tim




Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Welcome to the Ranch

I have added code tags, which you should always use; you can see how much better it looks now. I have also removed some of the excess blank lines. You should use spaces for indenting, not tabs.
I can’t tell whether you called the random generator right, because these ACM programs use their own API which I don’t have access to and I am not familiar with.
What happens? Does the program compile at all? Do you get an Exception at runtime.
Try replacing the random generator with a java.util.Random object.
There is something wrong about an int for sign. Try a boolean
boolean negative = myRandom.next...();
But that is going to cause difficulty when you print it out; you can print 1/2 or true/false, but from what I can see you won’t get +/−.
You can similarly get “random” ints from the Random object, but read the documentation carefully to see their range.
I would use a Scanner for the keyboard input, myself.

Why are you implementing Runnable for a single‑threaded application? And if the answer is, “that is how the app is structured,” find out why the app is structured like that. How are you calling that run() method? Are you doing something in your main method like new Thread(new MathQuiz()).start();? I tried that and it worked first time.
Tim Lai
Greenhorn

Joined: Dec 01, 2012
Posts: 2
thanks for the adjustments. well the program says there are multiple markers at the line of the instance of the randomgenerator.

it says to debug the current instruction pointer
and
watchpoint:MathQuiz[access modification] - rgen


i have already fixed the sign issue
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: The MathQuiz file doesnt seem to run i dont know why
 
Similar Threads
String assignment from method
How to get a random number
Number calculations
Program Problem