Does anyone know how to create a method that outputs a random number i created a code and i cant seem to get it right | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does anyone know how to create a method that outputs a random number i created a code and i cant seem to get it right

https://code.sololearn.com/cpd92Iz9X2xI/?ref=app

21st Oct 2017, 5:57 AM
jalen
jalen - avatar
9 Answers
+ 3
Here you go @Jalen, read my comments inside to know what's wrong. Hth, cmiiw https://code.sololearn.com/c6sNFNEEcV8u/?ref=app
21st Oct 2017, 6:44 AM
Ipang
+ 3
@Jalen, the code is pretty large, I think I'll need more time to analyze it, just letting you know. And SL app is restarting quite frequently, I lost track of changes in between :(
25th Oct 2017, 7:41 AM
Ipang
+ 2
You're welcome, I'm no Java guy anyway, but I read the logics, glad to help, keep it up!
21st Oct 2017, 7:02 AM
Ipang
+ 2
I see it, looks like you've been making improvements, the code gets bigger, I'll look into it, but I can't promise you anything, you see I'm just a student here in SL. I'll post back here when I have something to say, meanwhile, don't wait, it may take time :)
24th Oct 2017, 7:32 AM
Ipang
+ 2
@Jalen I think I need to understand the scenario of the game, I see that you tried to cope with many possibilities, using multiple nested ifs, I was wondering if arrays and loops can be used to simplify the complicated nested ifs. Tell me how, in each mode, we decide to say it's a win, draw or lose, and I see there's "1 vs 2", "1 vs 3", team subtraction" etc., what's the scenario with those modes? So far I've noticed that your code problem comes from imbalanced curly braces, looking at your code I can understand, with so much conditions it's easy to forget closing brackets. I also noticed you called sayNumber method in assignment, e.g int b = sayNumber(), you need to understand a method with void result type doesn't return anything, so the assignment is pointless. I think the sayNumber method needs to be changed, it should use loops to repeat printing random instead of having to be called multiple times. That's how far I've gone now, so now I'll wait for your response.
25th Oct 2017, 9:12 AM
Ipang
+ 1
thank you simple mistakes I made I'm still trying to get the hang of methods and this is going to help in the long run
21st Oct 2017, 7:00 AM
jalen
jalen - avatar
0
can you help me with my code again it would be much appriciated, it keeps outputting 'compilation error' and I can't figure out why? https://code.sololearn.com/cpd92Iz9X2xI/?ref=app
24th Oct 2017, 7:23 AM
jalen
jalen - avatar
0
thanks so much Ive got other projects so take your time if you can help me :)
24th Oct 2017, 7:34 AM
jalen
jalen - avatar
0
The scenario of the game is that it basically has multiple modes the user can choose from that have to do with dice. Also I was wondering if I should use do while loops instead of the else if statements and if it would qork. Also Im kind of confused on how to use the method over and over again in my code like I did, I figured it would be more easy than having to create the same loop over and over again for each case.
25th Oct 2017, 12:38 PM
jalen
jalen - avatar