I am trying to write a program that will switch any letter of the alphabet (upper or lower cases) AND number into the Phonetic alphabet. For example, if I enter "A" or "a" my program will give me (change it to) "Alpha". Moreover, if I enter "1" it will return "One". I've successfully managed to work the 'enter-any-letter' aspect of it, but my program does not recognize numbers. I tried putting int but my Scanner does not recognize this. I put a default in my code but still...no prevail. Should I use an if statement instead?
Further note: This is question is a continuation from this question
Here's what I've got so far:
import java.util.Scanner;
public class PhoneticTranslate {
public static void main(String[] args) {
int number = 0;
char letter;
String phonetic = null;
Scanner kb = new Scanner(System.in);
System.out.print("Please enter a letter or number: ");
letter = kb.next().charAt(0);
switch(Character.toUpperCase(letter))
{
case 'A':
phonetic = "Alpha";
break;
case 'B':
phonetic = "Bravo";
break;
// ... rest of cases for letters
case 'Z':
phonetic = "Zulu";
break;
default:
Scanner x = new Scanner(System.in);
number = kb.nextInt();
switch(number)
{
case '1':
phonetic = "One";
break;
case '2':
phonetic = "Two";
break;
// ... rest of cases for numbers
case '8':
phonetic = "Eight";
break;
case '9':
phonetic = "Nine";
break;
}
}
System.out.println("You Entered " + letter + ". This letter indicates: " + phonetic);
System.out.println("You Entered" + number + ". This number indicates: " + phonetic);
}
}