• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

not returning entire sentence

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Marshal
Posts: 73263
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and welcome to the Ranch
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic