Hi guys,
I'm almost finished my assignment. It's purpose is to translate english words to pirate language. For example, when some enters "hello", "ahoy" is returned. But when I enter two words like "pardon me", "null" is returned even though I have assigned "avast" to it. I'm thinking this is because I have included Console.readToken() instead of readString(). But token in my opinion works better. So I'm not sure what I can do for more than one word like "pardon me" or "excuse me". Can anyone help?

Here is the code:

import java.util.*; 
public class PirateTranslator
{
  public static void main(String [] args)
  {
   HashMap <String, Object> hashmap = new HashMap <String, Object>();
   hashmap.put("hello", "ahoy");                                        
   hashmap.put("madam", "proud beauty");
   hashmap.put("hi", "yo-ho-ho");
   hashmap.put("pardon me", "avast");
   hashmap.put("excuse me", "arrr");
   hashmap.put("my", "me");
   hashmap.put("friend", "me bucko");
   hashmap.put("sir", "matey");
   hashmap.put("madam", "proud beauty");
   hashmap.put("miss", "comely wench");
   hashmap.put("stranger", "scurvy dog");
   hashmap.put("where", "whar");
   hashmap.put("is", "be");
   hashmap.put("the", "th'");
   hashmap.put("you", "ye");
   hashmap.put("tell", "be tellin'");
   hashmap.put("know", "be knowin'");
   hashmap.put("how far", "how many leagues");
   hashmap.put("old", "barnacle-covered");
   hashmap.put("attractive", "comely");
   hashmap.put("happy", "grog-filled");
   hashmap.put("nearby", "broadside");
   hashmap.put("restroom", "head");
   hashmap.put("restaurant", "galley");
   hashmap.put("hotel", "fleabag inn");
   hashmap.put("pub", "Skull & Scuppers");
   hashmap.put("bank", "buried treasure");
   
   while(!Console.endOfFile())
   {
   
     String input = (String) hashmap.get(Console.readToken());
   
     System.out.print(input);
     System.out.print(" ");
   }
   
  }
}

"But token in my opinion works better"
Obviously not. If the input can be multiple words separated by blanks then either you have to loop reading all the tokens on the line then concatenate them again, or just read the whole line.

Hello,
I copyed the code and pasted in the coding program but i saved it but how can i then test it do i need to ad another code to see it in a program thing?
and what code?

Julian, this is no reason to re-boot a dead thread. and really, if you don't know how to run that code, don't try. learn the basics of Java instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.