Advertisement
cd62131

English Japanese Dictionary

Jan 23rd, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.32 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Map.Entry;
  3. import java.util.Scanner;
  4. import java.util.TreeMap;
  5.  
  6. public class EnglishJapaneseDictionary {
  7.   public static void main(String[] args) {
  8.     Scanner in = null;
  9.     try {
  10.       in = new Scanner(System.in);
  11.     }
  12.     catch (Exception e) {
  13.       System.exit(1);
  14.     }
  15.     Map<String, String> dict = new TreeMap<String, String>();
  16.     while (true) {
  17.       System.out.println("<メニュー選択> 1.追加、2.削除、3.検索、4.一覧表示、5.終了");
  18.       int choice = new Integer(in.nextLine());
  19.       if (choice == 1) {
  20.         System.out.println("追加する英単語");
  21.         String word = in.nextLine().trim();
  22.         System.out.println("意味");
  23.         dict.put(word, in.nextLine().trim());
  24.       }
  25.       if (choice == 2) {
  26.         System.out.println("削除する単語");
  27.         dict.remove(in.nextLine().trim());
  28.       }
  29.       if (choice == 3) {
  30.         System.out.println("検索する英単語");
  31.         System.out.println("意味は" + dict.get(in.nextLine().trim()) + "です");
  32.       }
  33.       if (choice == 4) {
  34.         for (Entry<String, String> e: dict.entrySet()) {
  35.           System.out.println(e.getKey() + " " + e.getValue());
  36.         }
  37.       }
  38.       if (choice == 5) break;
  39.     }
  40.     in.close();
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement