Is there a way to compare the variable for each thread
Norm Radder wrote:
Is there a way to compare the variable for each thread
What problem are you having doing that? variables that are in scope would be accessible from any thread. The only problem would be conflicting uses of the variables from different threads.
Are those values held in a variable? Where are those variables defined?speed of the horse is generated in random number
how can I compare the distancetravelled of each thread/horse
Norm Radder wrote:
how can I compare the distancetravelled of each thread/horse
Where are those variables defined? Are they in scope everywhere you want to access them?
Note: The posted code has many formatting problems.
There are too many hidden }s at the end of statements.
Some of the code within loops is not indented.
These coding problems make the code harder to read and understand.
Be sure to fix these formatting before posting the new version of the code.
how can I compare the distancetravelled
Norm Radder wrote:
how can I compare the distancetravelled
Use the list of Horse class instances to access the distancetravelled variable for each Horse by calling its get method.
Norm Radder wrote:NOTE: The posted code still has formatting problems as I described earlier. Please fix them. I don't try to work with poorly formatted code.
I assume you know how to write a loop that goes through the items in a list.
Inside that loop, put the logic for what you want to do with the values in the items in the list.
Norm Radder wrote:Post again when the code has been formatted and when it can be compiled and executed for testing.
done. the code is now updated
Norm Radder wrote:
done. the code is now updated
Sorry, there are still compiler errors in it. Please fix the errors and post a clean copy.
If you are having problems understanding the errors, copy the full text of the error message and paste it here.
Norm Radder wrote:Ok, that's better. I am able to compile and execute the code.
Now, what changes are you trying to make?
Norm Radder wrote:When do you want to compare the distancetravelled values for the Horses?
Once every time unit
Or every time a change is made?
I like to compare it every time unit
where should I place that in my code.
give me an example
list.get(i). getDistanceTravelled()
Norm Radder wrote:
list.get(i). getDistanceTravelled()
Yes. If the list has Horse objects, then that code would access the distanceTravelled for one of the objects in the list.
how can I compare that
Norm Radder wrote:
how can I compare that
The list has all the Horse objects. You can access any and all of the contents of the list by using the List interface's get() method.
For example to compare the first two elements of the list to see if the first has travelled farther then the second element:
(list.get(0). getDistanceTravelled() > list.get(1). getDistanceTravelled())
Norm Radder wrote:What do you want to change about the displayed results?
Post the current program's output
and an example of what you want to see instead.
What should be displayed for a tie?
There are three kinds of actuaries: those who can count, and those who can't.
I want the comparison every changes in distancetravelled after the hopped in run method
how to compare each distancetravelled to other horses distancetravelled. How can I do this.
compare horse1 distancetravelled to other horses
then horse2 distancetravelled to other horses
then horse3 distancetravelled to other horse
and so on.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:can you explain why you need this Thread.sleep(1000)?
a way to write a race program without using thread.sleep?
Don't get me started about those stupid light bulbs. |