Skip to content

Instantly share code, notes, and snippets.

@Viacheslav77
Last active March 1, 2016 22:39
Show Gist options
  • Select an option

  • Save Viacheslav77/ab35bcff717fc53debea to your computer and use it in GitHub Desktop.

Select an option

Save Viacheslav77/ab35bcff717fc53debea to your computer and use it in GitHub Desktop.
Написать программу переводчик, которая будет переводить текст, написанный на одном языке, на другой язык согласно заранее составленному словарю
package Dictionary;
import java.util.HashMap;
import java.util.Map;
public class Dictionary {
private Map <String,String> Dic;
public Dictionary (){
Dic = new HashMap <String,String> ();
}
public void setWord (String w1, String w2){
Dic.put(w1, w2);
}
public String getW2 (String w1){
return Dic.get(w1);
}
public String getW1 (String w2){
return Dic.get(w2);
}
public void getTransfer(String text,Dictionary d ){
System.out.println ("Фраза для перевода - " + text + "\n переводим ...");
String [] tmp = text.split(" ");
StringBuilder sb = new StringBuilder ();
for(String s: tmp)
sb.append(d.getW2(s)+" ");
System.out.print("Перевод : " + sb);
}
}
package Dictionary;
/*Написать программу переводчик, которая будет переводить текст,
написанный на одном языке, на другой язык согласно заранее
составленному словарю.*/
public class MyClass {
public static void main(String[] args) {
String [] s1 = {"Hello", "!", "world", "My", "name"};
String [] s2 = {"Привет","!", "мир", "моё", "имя"};
Dictionary d = new Dictionary();
for(int i=0; i < s1.length; i++)
d.setWord(s1[i], s2[i]);
String text = "Hello world !";
d.getTransfer(text, d);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment