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

In java please, Problem 1 Write a new program RomanNumeralslI 1 and 10 (inclusi

ID: 3728997 • Letter: I

Question

In java please,

Problem 1 Write a new program RomanNumeralslI 1 and 10 (inclusi number (see http://en.wikipedia.org/wiki/Roman numerals). The difference between this program to ask for and validate that the entered number is in the correct range number i one in the correct if-else in the main prog am named RomanNumeralslI that prompts the user to enter an integer between ve). The program should then display the Roman numeral equivalent for that and the RomanNumeral program in lab 4 is that this program will use a separate method and force the user to enter a n the specified range. It should keep prompting the user to enter integers until they enter t range. Since the user has to enter a number in the correct range to continue, the ram no longer needs to handle numbers that are not in the correct range. Example 1: Enter an integer from 1 to 10 (inclusive): 4 The Roman numeral for 4 is IV. Example 2: Enter an integer from 1 to 10 (inclusive): 3 -3 is not a valid choice. Enter an integer from 1 to 10 (inclusive)2 The Roman numeral for 2 is II. Example 3: Enter an integer from 1 to 10 (inclusive): 347 347 is not a valid choice Enter an integer from 1 to 10 (inclusive): -9 -9 is not a valid choice. Enter an integer from 1 to 10 (inclusive): o 0 is not a valid choice. Enter an integer from 1 to 10 (inclusive): 9 The Roman numeral for 9 is IX

Explanation / Answer

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
class roman{

public static String RomanNumerals(int Int) {
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
roman_numerals.put("M", 1000);
roman_numerals.put("CM", 900);
roman_numerals.put("D", 500);
roman_numerals.put("CD", 400);
roman_numerals.put("C", 100);
roman_numerals.put("XC", 90);
roman_numerals.put("L", 50);
roman_numerals.put("XL", 40);
roman_numerals.put("X", 10);
roman_numerals.put("IX", 9);
roman_numerals.put("V", 5);
roman_numerals.put("IV", 4);
roman_numerals.put("I", 1);
String res = "";
for(Map.Entry<String, Integer> entry : roman_numerals.entrySet()){
int matches = Int/entry.getValue();
res += repeat(entry.getKey(), matches);
Int = Int % entry.getValue();
}
return res;
}
public static String repeat(String s, int n) {
if(s == null) {
return null;
}
final StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++) {
sb.append(s);
}
return sb.toString();
}

public static void main(String args[]){
int c=0;
while(c==0){
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter an integer");
int myint = keyboard.nextInt();
if(myint>0 && myint<10){
System.out.println("The roman number for "+myint+" is: "+RomanNumerals(myint));
c=1;
}
}
}
}

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