APlusGrades

Not Rated (0)

$15/per page/Negotiable

About APlusGrades

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing,Foreign Languages,Geography,Geology,Health & Medical,HR Management,Law,Management,Physics,Programming,Science,Statistics Hide all
Teaching Since: Jul 2017
Last Sign in: 272 Weeks Ago, 1 Day Ago
Questions Answered: 1850
Tutorials Posted: 1850

Education

  • Graduate in Biology and Nutrition, MBA Finance
    Florida State University
    Aug-2000 - Jul-2007

Experience

  • Ass. Relationship Manager
    Penn-Florida
    Mar-2009 - Feb-2016

Category > Computer Science Posted 21 Jul 2017 My Price 12.00

write a Java program

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:

  1. Start with an empty String containing your Roman numeral
  2. While your number is not zero
    1. Modulo your number by 10 to get the final digit
    2. Append the value of your digit to the front of your Roman numeral based on the tables above and your current position (ones, tens, hundreds, thousands)
    3. Divide your number by 10 to move to the next position

So for example, the number 87 could be converted to a Roman numeral bythis process:

  • Start with an empty String: ""
  • The number 87 != 0
    • 87 % 10 = 7
    • 7 in the ones position is 7 - "VII"
    • Append this to the front of our String: "VII"+"" = "VII"
    • 87  / 10 = 8 (Remember - integer division here, no remainder)
  • The number 8 != 0
    • 8 % 10 = 8
    • 8 in the tens position is 80 - "LXXX"
    • Append this to the front of our String; "LXXX"+"VII" = "LXXXVII"
    • 8 / 10 = 0
  • The number 0 == 0
  • Our final result is: LXXXVII

 

 

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). 

Answers

Not Rated (0)
Status NEW Posted 21 Jul 2017 01:07 PM My Price 12.00

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

Not Rated(0)