# Purpose

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.

# Requirements

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.

# Think before programming

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.

## Hints

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:

1. Isolate the number of “ones”. (Looking at “HOW TO 2.1” starting on page 55 might help)
2. Isolate the other digits: Tens, Hundreds, and Thousands.
3. Having isolated each digit, produce the correct set of letters.

# Getting Help

If you get stuck…

• Write small parts of your program and then test them, and do the simpler things first. For example, write a program that deals with just an integer between 1 and 10, and then look for patterns that might help you expand your program's functionality from there.
• Talk to your friends about the problem and describe your approach to them. Sometimes your ideas will become clearer as you explain them to someone else.
• You can ask the TA to listen your ideas, but do not let them solve the problem for you.

# Pass-off procedure

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:

1. Show the TA your test cases, with the input and correct output (manually written). You will be graded on the diversity of your tests, so 1234, 1235, 1236 will not be well received. You should have about 15 tests. Note that you get these points for just writing the test cases, no programming required. (5 points)
2. As you start to write a program to do the conversion, start with small simple steps as listed here. Note that you do not have to show the TA each step individually. The TA will simply check that your program accomplishes each of these elements:
1. Can your program read in a single decimal digit (just 1-9) and print the corresponding roman number (I-IX)? (5 points)
2. Can it isolate the decimal number of “ones” in the input value 2345 (that is 5)? (5 points)
3. Can it isolate the decimal number of tens, hundreds and thousands? (5 points)
4. Can it convert each of the decimal numbers you found into the corresponding roman numbers and print the corresponding roman number? (5 points)
3. Is your code properly formatted (indenting blocks, comments, spacing, reasonable names of variables)? (5 points)

10% extra credit: Make another program that converts back, that is, takes in a roman number and produces the corresponding decimal number.