Forums Register Login

Using Lists/ArrayLists, code doesn't work

+Pie Number of slices to send: Send
Hello,

I'm trying to pass a Model (the name of a class) into a method but I'm not getting any results, here is the code;



The output I get is nothing, when it should just generate 10 number 1's. As the player1 and player 2 WS variable values are different. I've tracked the problem down to the "If player1.WS > player2.WS" line in the code, I'm not sure why it doesn't make a comparrison between the two different instances of the Model class.

Can anyone please suggest why my code isn't working as I expected?

Thanks
+Pie Number of slices to send: Send
Based on that code, I wouldn't expect any output. You just add the models to the list - you don't do anything with them. Is there something missing?
+Pie Number of slices to send: Send
Oh dear, Just made an epic fail.

I didn't call the method...

Thanks for pointing that out to me, I'll get back to you if the problem I mentioned keeps happening.
+Pie Number of slices to send: Send
Hi,

I think that you should use to compare object the Comparable Interface.

Look here:
Inteface
+Pie Number of slices to send: Send
I called the method that outputs (using System.out.println) text on the screen but still I don't get anything, any ideas why?

Here is is the slightly updated code;




Thanks again
+Pie Number of slices to send: Send
You're passing the same Model object to closeCombatHitting for both parameters. Which means that player1 == player2, so neither test will work.

I don't quite know what you're intending to happen, but maybe you need something like this?
+Pie Number of slices to send: Send
Thanks for pointing that out, I've corrected it and my program does what I wanted it to do.

Just so I know, would this be a good way to remove the last element in a list?

Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 911 times.
Similar Threads
how to access instance variables
Having NullPointerException Error in Connect4
working with Scanner
Struggling with using methods from objects in another class
Please help, java program terminating unexpectedly without reason
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:41:17.