Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 02-26-2006, 01:30 AM   #1 (permalink)
 
Newb Techie

Join Date: Feb 2006

Posts: 32

Aesthetic

Send a message via AIM to Aesthetic
Default Java help, please.

I have to make a Calculator that works something like this:

user enters in: six times five
output: 6 x 5 = 30

i am making the text the user enters a string, but i don't know how to convert from a string to an integer. meaning, i don't know how to make six = 6.

does anybody know? the parseInt method only takes an int from a string, and makes it an int. but how do you make text an int?

any help you could offer would be great. i am just a beginner with Java, and i'm trying to learn the ropes.

thanks.
Aesthetic is offline  
Old 02-26-2006, 02:28 AM   #2 (permalink)
 
Super Techie

Join Date: Jun 2005

Posts: 274

mgoldb2

Default

depends how large the numbers need to be. if you limiting too 1-9 then I would just use a giant if-else statement to map each string to a number meaning

if(string=="one"
int = 1
else if(string=="two)
int = 2
.
.
.
.
else if(string=="nine")
int = 9
else
"invalid input"

now of corce this not a reasonable soulution if you need more then 1-9
mgoldb2 is offline  
Old 02-26-2006, 11:42 AM   #3 (permalink)
 
Super Techie

Join Date: May 2005

Posts: 479

furtivefelon

Default

you could use java dictionary to store complementary pairs.. then use the methods in there to get your desired #

However, if you store 6 as "6", i believe you can simply use casting.. Though i remember you have to do a bit more than casting, specifics i have fogotten..
__________________
lisp hacker
running: FreeBSD 5.4 - still learning
develop with: SBCL + emacs for lisp, Anjuta IDE +gcc for c, SPE for python..
browse with: opera
furtivefelon is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On