Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

I Messed Up With My Thread Code

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use Thread to generate some random numbers and I got some compilation errors:


.\CustomizedRandomNumGenerator.java:6: cannot resolve symbol
symbol : variable start
location: class CustomizedRandomNumGeneratorService
service = new CustomizedRandomNumGeneratorService().start;
^
.\CustomizedRandomNumGenerator.java:18: cannot resolve symbol
symbol : variable ranNum
location: class CustomizedRandomNumGenerator
return ranNum;


I have a main program that is supposed to display 5 random numbers:

The RandomNumberGenerator is an interface with a getRandom(); method to be implemented:

The CustomizedRandomNumGenerator implements the RandomNumberGenerator and starts a thread in the getRandom(); method. And it is the class where compilation errors occurred.

The code in the CustomizedRandomNumGeneratorService looks like:
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My goodness. You did say this had something to do with a job interview, didn't you? I suspect that you're going to have some real problems doing this job, if you get it. The answers to both of these are really very obvious.

Would you like to practice for your new job by thinking about these errors, and then posting your guesses in this thread -- or do you want us to just give you the answers? If you get a job as a programmer, you're going to have to get used to figuring this sort of thing out for yourself.

So what will it be?
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint #1: What's the difference in syntax when referring to an object's variable and invoking an object's method?
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm kinda with Ernest here. The code you have here shows many things, none of them good. My suggestion would be do delete the whole mess and spend a couple hours understanding how threads work.

P.S. the Thread.sleep(5) call in your code has no effect on your 'random number generater' thread.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have come up with a clean skeleton (without compilation error). But, the code does not generate random numbers as it is coded:

and
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint: What is the variable that you are returning as a random number? And what is the variable you are using to generate the random number? ...

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic