Question: Converts Roman numerals to decimal value. For example, if the Roman numeral is X then the valueOf method returns 10 The valueOf method assumes the

Converts Roman numerals to decimal value. For example, if the Roman numeral is X then the valueOf method returns 10
The valueOf method assumes the parameter is one of either: I X L C D M
*/
import java.util.Scanner;

public class RomanNumerals
{
public static void main(String[] args)
{
   Scanner in = new Scanner("I C X D M L");

   char romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 1") ;
   
   romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 100") ;
   
   romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 10") ;
   
   romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 500") ;
   
   romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 1000") ;
   
   romanNumeral = in.next().charAt(0);
   System.out.println("Value: " + valueOf(romanNumeral) + "   Expected: 50") ;
}

/**
Returns the integer value of the given Roman numeral (one of I X L C D M)
@param numeral a single Roman numeral (char)
@return the integer value of numeral
*/
//-----------Start below here. To do: approximate lines of code = 14
// write a static method valueOf with the appropriate parameters and return type.

Step by Step Solution

3.40 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static int valueOf char ch if ch ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!