Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 272 Weeks Ago, 1 Day Ago |
Questions Answered: | 1850 |
Tutorials Posted: | 1850 |
Graduate in Biology and Nutrition, MBA Finance
Florida State University
Aug-2000 - Jul-2007
Ass. Relationship Manager
Penn-Florida
Mar-2009 - Feb-2016
For this lab you will write a Java program that manipulatesnumbers. The program will ask the user to enter a number (or azero to quit) and then convert that number into a Roman numeral anddisplay the result. The program will loop until the user enters azero to end the program.Â
Â
For this assignment you must start with the following "skeleton" ofJava code. Import this into your Eclipse workspace and fill inthe methods as directed. Feel free to add any methods you find useful, but make sure that youadd comments indicating what they do following the form of the rest ofthe comments in the code.
Â
Project08.java
Roman Numerals vs. Decimal Numbers
The following table shows the values of individual Roman numerals:
Â
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
Â
Here is a table of the digits from 1 to 9 in the Roman system:
Â
I | 1 |
II | 2 |
III | 3 |
IV | 4 |
V | 5 |
VI | 6 |
VII | 7 |
VIII | 8 |
IX | 9 |
Â
Note that the Roman system in general is an additive system - the valuefor "VII" is determined by adding the value for the symbol "V" (5) tothe value for the symbols "I" and "I" (1+1) to get a total of 7. The exceptional cases are where a symbol has a value that is smallerthan the value of the symbol that comes after it - such as the case for"IV" (4) and "IX" (9). Here the smaller value is subtracted from the larger valueinstead.
Â
This rule holds true for all place values. Here is a table of thevalues between 10 and 90, by tens:
Â
10 | X |
20 | XX |
30 | XXX |
40 | XL |
50 | L |
60 | LX |
70 | LXX |
80 | LXXX |
90 | XC |
Â
And here is a table of the values between 100 and 900, by hundreds:
Â
100 | C |
200 | CC |
300 | CCC |
400 | CD |
500 | D |
600 | DC |
700 | DCC |
800 | DCCC |
900 | CM |
Â
To build more complex values than these, Roman numerals use a systemwhere, like the decimal system, there are"place values" for thousands, hundreds, tens and ones. Forexample,the decimal number 1986 has a 6 in the "ones" place, an 8 in the "tens"place, a 9 in the "hundreds" place and a 1 in the "thousands"place. To determine the value of the number you add 1x1000 + 9x100 + 8x10 +6x1.
Â
Place values in the Roman system operate a bit differently, becauseeach place can have multiple symbols instead of just one. So toget the equivalent Roman numeral for a number we look at each placeindividually and concatenate the strings for each positiontogether. For example, if we want to know the Roman numeralrepresentation of 1986 we break it down into its component pieces:
Â
1000 - M
+900 - CM
+ 80 - LXXX
+Â 6 - VI
Â
So as a Roman numeral, 1986 would be represented by the String"MCMLXXXVI".
Â
Converting from Decimal Numbers to Roman Numerals
To convert from a decimal number to a Roman numeral, you can take eachdigit of the number in turn and concatenate the Roman numeral valuesfor each position together in order. One algorithm for doing thisis:
So for example, the number 87 could be converted to a Roman numeral bythis process:
Â
Â
Project 08 Sample Output
This is a sample transcript of what your program should do. Itemsin bold are user input andshould not be put on the screen by your program.Â
Â
Enter a number between 1 and 3999 (0 to quit): 1984
The number 1984 is the Roman numeral MCMLXXXIV
Â
Enter a number between 1 and 3999 (0 to quit): 10
The number 10 is the Roman numeral X
Â
Enter a number between 1 and 3999 (0 to quit): 4000
ERROR! Number must be between 1 and 3999
Â
Enter a number between 1 and 3999 (0 to quit): 3999
The number 3999 is the Roman numeral MMMCMXCIX
Â
Enter a number between 1 and 3999 (0 to quit): 0
Goodbye!
Â
Â
Note that your output depends on the choices made by theuser. Remember to check that the user inputs a number to convert that is withinrange (between 1 and 3999).Â
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- -----------Tha-----------nk -----------you----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m Â----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I