I am new to Java (along with programming in general). I was working on a personal project where a user types one character to which it is converted to another character. More specifically, a user would type a romanization of a Japanese character to which the Japanese hiragana equivalent is outputted. I am using two separate classes at the moment:
RomaHiraCore.java
import java.util.*;
public class RomaHiraCore
{
public static void main(String[] args)
{
Table.initialize(); // Table.java needed!
Map<String, String> table = Table.getTable();
Scanner roma = new Scanner(System.in);
System.out.println("Romaji: ");
String romaji = roma.nextLine().toLowerCase();
if (table.containsKey(roma))
{
System.out.println(table.get(roma));
}
else
{
System.out.println("Please enter a valid character (e. g. a, ka)");
}
roma.close();
}
}
Tables.java
import java.util.*;
public class Table
{
private static Map<String, String> table = new LinkedHashMap<>();
public static Map<String, String> getTable()
{
return table;
}
public static void initialize()
{
// a - o
table.put("a", "あ");
table.put("i", "い");
table.put("u", "う");
table.put("e", "え");
table.put("o", "お");
// ka - ko
table.put("ka", "か");
table.put("ki", "き");
table.put("ku", "く");
table.put("ke", "け");
table.put("ko", "こ");
}
}
If anyone can point me in the right direction, I would greatly appreciate it. I've attempted to go over the documentation, but I can't seem to grasp it (maybe I'm overthinking it). When I run the program, it allows me to enter a character; however, it will only continue to the "else" statement rather than scan Table.java to see if the input matches any of the values listed. Either I'm overlooking something or need to use an entirely different method altogether.