Help coderanch get a
new server
by contributing to the fundraiser
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
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

Write a method calles diceSum

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
Hi, I am having a little trouble understanding why I am not getting this right, I followed all the steps in the book and it still came out wrong, help please!

Write a method called diceSum that accepts a Scanner for the console as a parameter and prompts for a desired sum, then repeatedly simulates the rolling of 2 six-sided dice until their sum is the desired sum. Here is a sample dialogue with the user:

Desired dice sum: 9

4 and 3 = 7

3 and 5 = 8

5 and 6 = 11

5 and 6 = 11

1 and 5 = 6

6 and 3 = 9

So what am i not understanding?

Bartender
Posts: 6109
6
• Number of slices to send:
Optional 'thank-you' note:
Hi, and welcome to the Ranch!

Folks here will be better able to help you if you TellTheDetails(←click) about exactly what's not working for you or what you're not understanding.

Jeff Verdegan
Bartender
Posts: 6109
6
• Number of slices to send:
Optional 'thank-you' note:
Off the bat, though, I will ask you to explain exactly why you put this line in and what you think it will do:

Ranch Hand
Posts: 859
• Number of slices to send:
Optional 'thank-you' note:
You never read the desired result (i.e: 9 from the scanner).

You have hardcoded the "desired result" of 7 at line 11.

WP

Bartender
Posts: 825
5
• Number of slices to send:
Optional 'thank-you' note:

Here is a sample dialogue with the user:
...

It's certainly not from the code you posted, since that one can't even be compiled.

Sora McKain
Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:

Jeff Verdegan wrote:Off the bat, though, I will ask you to explain exactly why you put this line in and what you think it will do:

Well I get an error that says

Dice.java:6: illegal start of expression
r.nextInt=();
^
1 error

so thought I might need that line but it obviously does no good.

Jeff Verdegan
Bartender
Posts: 6109
6
• Number of slices to send:
Optional 'thank-you' note:
That sounds like Programming By Accident. Not a particularly effective approach.

It's okay to guess sometimes, but if you do, make sure you at least have some expectation of what each piece means and why it might work.

So, for instance, when you write

don't just do it because you're sticking arbitrary symbols together. If you have a theory as to what each piece of that line might mean, and why you might need it, then sure, try it out, see if your theory holds up. But just reaching into the blind grab bag and throwing together whatever happens to come out--an - sign here, some parentheses there--is something to be avoided always.

Sora McKain
Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
Thanks to all for your help, I have figured out my problem (I also figured out that this is not something I should be doing on little to no sleep lol).

Once again thank you. If I have problems in the future I will be sure to ask.

 Arthur, where are your pants? Check under this tiny ad. We need your help - Coderanch server fundraiser https://coderanch.com/t/782867/Coderanch-server-fundraiser