Question

My prof provided me with a bunch of methods to fill in for a roman numeral program (in additive format, so 4=IIII, 9=VIIII, etc.)

I'm having trouble understanding what the difference is between these two methods:

   **
   * This method prints, to the standard output and in purely additive
   * notation, the Roman numeral corresponding to a natural number.
   * If the input value is 0, nothing is printed. This
   * method must call the method romanDigitChar(). 
   * @param val   ?
   */

    public void printRomanNumeral(int val)
    {

    }

   **
   * This method returns the Roman numeral digit corresponding
   * to an integer value. You must use a nested-if statement.
   * This method cannot perform any arithmetic operations. 
   * @param val  ?
   * @return     ?
   */

    public char romanDigitChar(int val)

    {

    }

Is romanDigitChar supposed to read a number digit by digit, and only return one digit at a time? If so, I don't understand how printRomanNumeral would go about calling it.

I've researched other roman numeral programs, but I can't seem to find any that use methods called within other methods like this one that I could compare it to.

Any advice is appreciated!

Was it helpful?

Solution

I assume romanDigitChar returns one char for an exact matching numbers e.g. 1, 5, 10, 50, 100 etc only. printRomanNumeral would call this repeatedly for known values as numbers to turn them into characters. I suggest two nested loops, one for amounts with specific characters in decreasing value and one extracting each value. The inner loop calls the second method.

I assume he/she expects ASCII characters although there are special Unicode characters for Roman numerals.

OTHER TIPS

Well for starters, romanDigitchar returns a char (the Roman Numeral corresponding to the natural number given as input). printRomanNumeral doesn't return anything, but is supposed to print the Roman numeral.

Is romanDigitChar supposed to read a number digit by digit, and only return one digit at a time? Yes, for instance if you want to print two roman numeral digits: IIII, VIIII. In your void printRomanNumeral(int val)method,you need to do:

public void printRomanNumeral(int val)
{
         System.out.println(romanDigitChar(4));
         System.out.println(romanDigitChar(9));          
}

But in your char romanDigitChar(int val) method, you need to have some sorts of algorithm to convert natural number to roman number, something like:

    public char romanDigitChar(int val)
    {

        if(val == 4) {
          //Return a roman digit 4.
        }
        if(val == 9) {
          //Return a roman digit 9.
        }

      }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top