I'm working on a calculator program that has 4 modes.
Binary(base 2), octal(base 8), decimal(base 10), and hexadecimal(base 16).
I want to know how I can check if the user input that is entered matches the current mode. For example if the calculator is set to octal mode how do I check if what the user entered is in base 8? Or if it's in hexadecimal mode how to check if it's base 16?
The program starts in decimal mode and displays this menu.
private static String displayMenu(String mode) {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
System.out.println(mode + " mode\n");
System.out.println("Bin - Binary +");
System.out.println("Oct - Octal -");
System.out.println("Dcm - Decimal *");
System.out.println("Hex - Hexadecimal /");
System.out.println("Q - Quit =");
System.out.print("Option or value: ");
String option = input.nextLine();
option.toUpperCase();
return option;
}
The user can either change the mode or enter a value for the current mode.