Write a program that asks the user to enter a number within
Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number. Input Validation: Do not accept a number less than 1 or greater than 10. Prompts And Output Labels. Use the following prompt for input: \"Enter a number in the range of 1 - 10: \". The output of the program should be just a Roman numeral, such as VII. CLASS NAMES. Your program class should be called RomanNumerals This program has to be done for JAVA
Solution
RomanNumerals.java
import java.util.Scanner;
class RomanNumerals
{
public static void main(String[] args) {
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get a number from the user.
System.out.print(\"Enter a number in the range of 1 - 10: \");
int number = keyboard.nextInt(); // User inputed number
//close stream
keyboard.close();
// Get Roman numeral.
String romanNumerals = convertNumberToRomanNumeral(number);
// Output to user
System.out.println(romanNumerals);
}
static String convertNumberToRomanNumeral(Integer number) {
switch (number) {
case 1:
return \"I\";
case 2:
return \"II\";
case 3:
return \"III\";
case 4:
return \"IV\";
case 5:
return \"V\";
case 6:
return \"VI\";
case 7:
return \"VII\";
case 8:
return \"VIII\";
case 9:
return \"IX\";
case 10:
return \"X\";
default:
return \"Invalid number.\";
}
}
}
Output:-

