Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that allows the user to enter an integer between 1 and 10

ID: 3652369 • Letter: C

Question

Create an application that allows the user to enter an integer between 1 and 10 into a text box on a form. Use a "Select Case" statement to identify which Roman numeral is the correct translation of the integer. Display the Roman numeral in a Label control. If the user enters an invalid value, display an appropriate error message and do not attempt the conversion. Include an Exit button closes the window.

The following table lists the Roman numerals for the numbers 1 through 10.
Number Roman Numeral
1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VIII
9 IX
10 X
*Input validation: Do not accept a number less than 1 or greater than 10. If the user enters a number outside this range, display an error message.

Explanation / Answer

import java.io.*; import java.util.Scanner; public class Problem_89 { public static String westernToRoman(int western) { int level=7; String roman = ""; while(level>0) { if(western - levelToValue(level)>=0) { roman += String.valueOf(levelToNumeral(level)); western -= levelToValue(level); } else { //Check to see if you should use subtraction int subtractorLevel = (int)Math.floor(level/2)*2-1; if(subtractorLevel>0 && western-(levelToValue(level)-levelToValue(subtractorLevel))>=0) { western -= (levelToValue(level)-levelToValue(subtractorLevel)); roman = roman + levelToNumeral(subtractorLevel) + levelToNumeral(level); } level--; } } return roman; } public static int romanToWestern(String roman) { int western = 0; //the numerical version char currentChar; char nextChar; int i=0; while(i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote