-6

I am trying to make an app with java where you input a sentence, and the app changes the letters to other specified letters. What I need to know is how to do a "text input" and how to change the letters. Currently, I am not getting any errors, but all I get back is "testing." It makes sense, but how do I fix it? Here is what I have so far:

public class baseCoder {

    public static void main(String[] args) {
String t1 = "testing";      
String c = "a";
String f = "b";
String h = "c";
String j = "d";
String s = "e";
String q = "f";
String r = "g";
String u = "h";
String l = "i";
String e = "j";
String w = "k";
String m = "l";
String t = "m";
String i = "n";
String p = "o";
String o = "p";
String b = "q";
String v = "r";
String x = "s";
String a = "t";
String k = "u";
String n = "v";
String y = "w";
String g = "x";
String z = "y";
String d = "s";


    System.out.println("" + t1);
}
}
Tyler Mullins
  • 77
  • 3
  • 10
  • Uhm, and what code have you actually written that actually does anything? There's nothing to be fixed, your whole program still needs to be written, and that's not what SO is for. – Niels Keurentjes May 26 '13 at 23:44
  • 1
    You say you're trying but we don't see it! – Ravi K Thapliyal May 26 '13 at 23:45
  • seems that you miss some key code lines, so that nobody can help you. – Stony May 26 '13 at 23:53
  • The code posted here works. You don't fix something that works. You just need to add the missing functionality. Add some code that is supposed to get an input or replace characters and if you have difficulty, then come with a specific question. – nakosspy May 27 '13 at 00:05

2 Answers2

2

First you would need to create a Map of all the letters:

Hashmap<String, String> map = new Hashmap<String, String>();
map.put("a", "c");
map.put("b", "f");
...

To get the translation of each letter you simply get the value from the map:

String translatedLetter = map.get(letter);

So now you would need to create a loop to translate the whole word one letter at a time. I would use a StringBuilder to keep track of each translated letter.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Should we be doing their homework? :) – Ravi K Thapliyal May 26 '13 at 23:56
  • I didn't to the homework. I introduced the OP to some classes that might be helpful in solving the problem. – camickr May 27 '13 at 00:05
  • I am pretty new to java, though i'm sure thats already obvious, would the `String translatedLetter = map.get(letter);` be the original letter or the new one? and how would I go about making a string builder? – Tyler Mullins May 27 '13 at 00:06
  • `be the original letter or the new one?` - try the code and see, that is how you learn. `how would I go about making a string builder?` - read the API to see how to use it. Search the forum/web for examples. You can't program is you don't learn how to do problem solving on your own. – camickr May 27 '13 at 00:08
0

using HashMap would right option only when you wanted to put only the specific letters replacingt the orignal one.. However, there are other procedure like using random number between 65 and 91 and replacing the corresponding value... if your requirement is just to geneate another string...

Pavan Kumar K
  • 1,360
  • 9
  • 11