Are you better than me? Then please show me my mistakes..
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:Where are you stuck?
- Starting this code from the OK button? Use an ActionListener or Action for the JButton.
- The algorithm itself? Well, you've already written down the steps to take. All you need to do is translate that into code:
-- one single number means >= 0 and < 10.
-- using "% 10" you can get the last digit.
-- using "/ 10" you can cut off the last digit.
Are you better than me? Then please show me my mistakes..
Darryl Burke wrote:Oh, and you can use a single JSpinner with a SpinnerDateModel and a JSpinner.DateEditor that has an appropriate date format pattern.
Are you better than me? Then please show me my mistakes..
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Greg Brannon wrote:The sum of the year, month, and day will be a number in the thousands, a 4-digit number.
You then break the 4-digit number apart into each of the 4 digits. if the number is 1987, what is:
1987 % 10 = ?
198 % 10 = ?
19 % 10 = ?
I leave to you how to get 198, 19, and then 1.
Then add the 4 results together, in this case 7 + 8 + 9 + 1 = 25.
If the result is > 10, repeat. Any time you're repeating something, consider generalizing the algorithm and writing it in a method. In this case the method might be
Good luck!
Are you better than me? Then please show me my mistakes..
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
jandries Aldum wrote:
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
I thought the idea was to reduce the values to a single digit. In which case both those dates will come out to 7 and today (20110718 or 18/7/2011) will come out as 2.Rob Spoor wrote: . . . What will be the difference between February 1st 2011 and January 2nd 2011? Both lead to 2014 as total. . . .
Campbell Ritchie wrote:
I thought the idea was to reduce the values to a single digit. In which case both those dates will come out to 7 and today (20110718 or 18/7/2011) will come out as 2.Rob Spoor wrote: . . . What will be the difference between February 1st 2011 and January 2nd 2011? Both lead to 2014 as total. . . .
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Greg Brannon wrote:It'll be interesting to see the cleaned up version so please share it when you're done.
Does your current approach work if age = 2001? Or, for your original example, if age = 1999? You may need to add some additional testing to determine if you should stop or continue with the algorithm.
Are you better than me? Then please show me my mistakes..
jandries Aldum wrote:hey, try this method:
hope it is what you wanted
Are you better than me? Then please show me my mistakes..
Are you better than me? Then please show me my mistakes..
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Campbell Ritchie wrote:Your code is difficult to readbecauseyouhavenotleftanyspacebetweentokens.
Not assign=age%10 but assign = age % 10, please. One space before and after each binary operator.
That code appears too specific. There is a simple and elegant way to do it with loops, which can be generalised for any integer.
Are you better than me? Then please show me my mistakes..