aspose file tools*
The moose likes Beginning Java and the fly likes numerology program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "numerology program" Watch "numerology program" New topic
Author

numerology program

Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
I have to do a numerology program for my Java class. The program takes as input the user's birthdate and name. The date has to be in mm/dd/yy format. Then we are supposed to break down the number, adding the digits of the date together, until it is a single digit, i.e., between 0 and 9.
My question is: what is the best way to do the conversion from String to individual ints? Or should I break the String down into constituent Strings? Someone suggested I do that, and then copy them into an array. I am not sure of the best way to do this. Basically, I just want to take a date, like 11/03/78 and add the individual numbers together, reducing them to one number, like this:
1 + 1 + 0 + 3 + 7 + 8 = 20 = 2 + 0 = 2
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
I had a similar problem except with time instead of date. I could find no shortcut, so I did it manually. The only thing I can think of to do is to parse the string up into individual characters. Then use the Wrapper classes to convert the string representations of the numbers into actual ints. Then you can add them normally.

------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud


Michael J Bruesch<br /><i>I code, therefore I am.</i>
Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
Is it better to use the wrapper classes than to break up the string and then cast to an int? I admit I am confused about how they are different. I know the wrapper classes are for converting primitive types to objects.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Michael's way is a good way. Jade, you cannot cast a String object to a primitive int. Try it. The wrapper classes have methods for converting in both directions: object <--> primitive.

There is more than one way to break up the String.

[This message has been edited by Marilyn deQueiroz (edited November 04, 2001).]


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
OK, I was confused. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: numerology program