• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not returning entire sentence

 
Mack fitz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First let me say that I am not a programmer or a student, just someone that dabbles with programs in their spare time. So please forgive me if my terminology is a bit off. I am trying to a simple slang translator using an array that I can place inside an applet later. I have it so it translates the word that is in the list but it leaves the rest of the sentence out. If anyone can point me in the right direction to achieve getting the full sentence including the words that get translated I would greatly appreciate it. here is what I have already. thanks for any help in advance.
 
James E Baker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mack fitz wrote:Hi,

If anyone can point me in the right direction to achieve getting the full sentence including the words that get translated I would greatly appreciate it. here is what I have already. thanks for any help in advance.

}


Hey Mack,

I'm not sure exactly what you're looking for. Could you give me an example of how you'd like the output to look? Right now, it looks like you'd get output like this:

convert it to slang
yes
awe yeah
 
Mack fitz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,

Thanks for your reply.
When someone enters a complete sentence such as: If you want my opinion java can be hard. it only returns "two cents" instead of: If you want my two cents java can be hard.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When someone enters a complete sentence such as: If you want my opinion java can be hard. it only returns "two cents" instead of: If you want my two cents java can be hard.


Thats because you are only printing out the content of that array index. What you need is an else to handle the words that do not match any in the translate list.
Remember you want to print something in each passing of the outer loop, the word in input or the translated one in translateList (hint: use System.out.print instead of System.out.println)
Another approach is to reconstruct the string by concatenating the words to a new string and print it out as whole after the loop
 
Mack fitz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks people... Ive got it all squared away... I guess we can mark it up to a brain fart..Ive done the same program using a hashmap and the old if then statement but figured I would try this since I wasn't to sure about it.

Out of curiosity In your professional opinions which way is more efficient.. or a more correct version of the three..hashmap, this array, or if/then.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mack fitz wrote:Out of curiosity In your professional opinions which way is more efficient.. or a more correct version of the three..hashmap, this array, or if/then.


It simply depends on what you need, arrays are great for numbered indexes and when you don't expect the array size to change. Hashmap is used when you need associative array with Object keys that maps to one value (in you instance I'd recommend the hashmap)
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic