Search code examples
javamethodsroman-numerals

What is the difference between these two methods? JAVA


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!


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.