• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rounding to the nearest twelve  RSS feed

 
Greenhorn
Posts: 13
Java Netbeans IDE Netscape
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is kinda... unconventional (Never heard that in programming before, have you?).

I'm taking mouse click coordinates in a Jpanel, and dividing each one into regions.
clicking between X coordinates 12 and 23 will count as column 1.
clicking between Y coordinates 0 and 11 will count as row 0.
clicking between X coordinates 60 and 71 will count as column 5.

So, without doing "if X < 11", "if X < 23" ad infinitum (actually ad 27132), how do I round to the nearest twelve?
 
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like division to me.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xander Jacob wrote:So, without doing "if X < 11", "if X < 23" ad infinitum (actually ad 27132), how do I round to the nearest twelve?


forget all about programming. in fact, turn off your computer. Get some paper, pencils, and erasers. figure out how YOU would do it with only those devices. If i gave you the number 18,497, what should you round it off to?

Once you know how to do it, write down the steps as if you were explaining them to a PHD in mathematics. Once those steps are crystal clear, revise them so that a grad student could follow them. Revise them again for a high school student. and revise them again until a 10 year old child could follow them.

ONLY when you have those steps figured out - and I literally want you to write them out - should you consider writing a single line of java.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote: . . . write down the steps as if you were explaining them to a PHD in mathematics. Once those steps are crystal clear, revise them so that a grad student could follow them. Revise them again for a high school student. and revise them again until a 10 year old child could follow them. . . .
If your Maths PhD chappie can understand them, then surely so can the ten‑year‑old
 
Xander Jacob
Greenhorn
Posts: 13
Java Netbeans IDE Netscape
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... a modulo of 12 evaluating to 0? I assumed that modulos only worked with ten. Thanks!
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Xander Jacob wrote:So... a modulo of 12 evaluating to 0? I assumed that modulos only worked with ten. Thanks!

Actually, Henry said 'division', not modulo (although what you say is also true). Perhaps this page will help to explain why.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!