thumb The purpose of this lab is to build a slightly bigger and more complex program.
You will be implementing some of the things we have learned about “if” statements and other control structures.
You will write a program that converts the regular numbers we use (decimal) into roman numerals. That is, for example, convert 1958 into MCMLVIII.
This problem comes from the programming problem P3.22 in the book. Note that as stated in the book, we will not test anything above 3,999.
For this program you will need to read in a number provided by your user and through a series of steps, print out the equivalent Roman number. In the previous two labs we worked on reading data in and printing it out, the processing of the data in between was relatively straight forward. In this lab you will have to think more about the transformation itself.
To start, try doing a few conversions on paper, what procedure do you follow when you do this? There is more than one way to think about this, so try doing it by hand a couple of different ways, some ways you may do this can be converted more easily to code than others. Find a way to define your procedure with simple steps that can later be converted into java statements. Write pseudo code for your process as described in the book. Part of the pass off procedure requires that you show the TA some “test cases”, that is, a set of inputs that you will try to verify that your program works. By doing the conversion a few times by hand you will have opportunity to think about how the process works and produce the test cases that you will need for the pass off.
It really is important for you to stop and think about this before you start. This problem has a simple solution, though this simple solution is repetitive (involves much of typing).
There are often multiple letters that represent a single digit; for example, “CM” represents the single digit “9” in the value 900. In the number 1958 (MCMLVIII) there is a set of characters that represent the thousands place (“M”), a set for the hundreds place (“CM”), a set for the tens (“L”), and a set for the ones (“VIII”).
Try to solve this problem step by step:
If you get stuck…
When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria:
10% extra credit: Make another program that converts back, that is, takes in a roman number and produces the corresponding decimal number.