![]() |
Java
1.0
|
Class for manipulating roman numerals. More...
Classes | |
class | ValueError |
Exception class. More... | |
Public Member Functions | |
roman () | |
Empty constructor. More... | |
roman (String r) throws ValueError | |
Constructor from a roman numeral. More... | |
roman (int i) | |
Constructor from an integer. More... | |
String | toString () |
Used to print a roman object. More... | |
int | toInt () |
Used to convert a roman object to integer. More... | |
Static Public Member Functions | |
static String | int2roman (int num) |
Converts an integer number to roman. More... | |
static String | int2Roman (int num) |
Converts an integer to roman. More... | |
static int | roman2int (String roman) throws ValueError |
Converts a roman numeral to decimal. More... | |
static String | validateRoman (String romano) |
Validates a roman numeral. More... | |
static void | main (String[] args) |
main function for testing. More... | |
Private Attributes | |
String | rnum = null |
hold the roman numeral of this object More... | |
int | inum = 0 |
hold the integer representation of the roman numeral of this object More... | |
Static Private Attributes | |
static String[][] | symbols |
table for mapping [decimal power, digit] to roman symbols More... | |
static Map< Character, Integer > | d = null |
dictionary for mapping roman symbols to decimals More... | |
static int[] | l = null |
list for mapping roman symbols to decimals More... | |
static String[] | rSymbols = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"} |
table for relating decimals to roman symbols: an ordered list of roman numerals More... | |
static int[] | decimals = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1} |
table for relating decimals to roman symbols: an ordered list of the decimal representation of roman numerals More... | |
Class for manipulating roman numerals.
Roman numerals, the numeric system in ancient Rome, uses combinations of letters from the Latin alphabet to signify values. The numbers 1 to 10, 50, 100, 500 e 1000 can be expressed in Roman numerals as follows:
In the Middle Ages, a horizontal line was used above a particular numeral, or parentheses placed around it, to represent one thousand times that numeral.
To compile:
To run:
Definition at line 29 of file roman.java.
roman.roman | ( | ) |
Empty constructor.
Definition at line 104 of file roman.java.
Referenced by int2Roman(), and main().
roman.roman | ( | String | r | ) | throws ValueError |
Constructor from a roman numeral.
r | roman numeral. |
ValueError | if the given roman numeral is invalid. |
Definition at line 114 of file roman.java.
References inum, rnum, roman2int(), and validateRoman().
roman.roman | ( | int | i | ) |
Constructor from an integer.
i | decimal numeral. |
Definition at line 130 of file roman.java.
References int2roman(), inum, and rnum.
|
static |
Converts an integer number to roman.
The decimal numeral system (also called base ten or occasionally denary) has ten as its base. It is the numerical base most widely used by modern civilizations.
Decimal notation often refers to a base-10 positional notation, such as the Hindu-Arabic numeral system; however, it can also be used more generally to refer to non-positional systems, such as Roman.
num | integer to be converted to roman. |
Definition at line 168 of file roman.java.
References baseConverter.itoa(), symbols, and toString().
Referenced by roman().
|
static |
|
static |
main function for testing.
args | an integer to be converted to roman. |
Definition at line 343 of file roman.java.
References TextIO.getAnyChar(), TextIO.getln(), TextIO.getlnInt(), int2Roman(), TextIO.peek(), TextIO.put(), TextIO.putln(), roman(), toInt(), toString(), and validateRoman().
|
static |
Converts a roman numeral to decimal.
roman | roman numeral to be converted to decimal. |
ValueError | if the given roman numeral is invalid. |
Definition at line 248 of file roman.java.
References l.
Referenced by roman().
int roman.toInt | ( | ) |
Used to convert a roman object to integer.
Definition at line 151 of file roman.java.
References inum.
Referenced by main().
String roman.toString | ( | ) |
Used to print a roman object.
Definition at line 141 of file roman.java.
Referenced by int2roman(), and main().
|
static |
Validates a roman numeral.
romano | roman numeral to be validated. |
Definition at line 283 of file roman.java.
References d.
|
staticprivate |
dictionary for mapping roman symbols to decimals
Definition at line 47 of file roman.java.
Referenced by validateRoman().
|
staticprivate |
table for relating decimals to roman symbols: an ordered list of the decimal representation of roman numerals
Definition at line 88 of file roman.java.
Referenced by int2Roman().
|
private |
hold the integer representation of the roman numeral of this object
Definition at line 98 of file roman.java.
Referenced by roman(), toInt(), and toString().
|
staticprivate |
list for mapping roman symbols to decimals
Definition at line 63 of file roman.java.
Referenced by roman2int().
|
private |
hold the roman numeral of this object
Definition at line 93 of file roman.java.
Referenced by roman(), and toString().
|
staticprivate |
table for relating decimals to roman symbols: an ordered list of roman numerals
Definition at line 84 of file roman.java.
Referenced by int2Roman().
|
staticprivate |
table for mapping [decimal power, digit] to roman symbols
Definition at line 34 of file roman.java.
Referenced by int2roman().