Bookmark Topic Watch Topic
  • New Topic

Roman Numeral Program  RSS feed

Frank White
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a program that takes in a string of integers and converts them into roman numerals. This part of the program is complete; however, part 2 of this program is to take in a string of roman numerals and change them to integers. The problem is part2. When I input IIIII it comes out 5. It should read V=5 not IIIII=5. IIIII is not a roman numeral. Is anyone familiar with this problem?

Thank you...Frank White

This is the code I have it will compile and run if you cut and paste.

public class ArabicNumeral extends NumberStringEva {

} // end of constructor

private int romanValue(char cAry){

switch (cAry){
case 'M':
return 1000;
case 'D':
return 500;
case 'C':
return 100;
case 'L':
return 50;
case 'X':
return 10;
case 'V':
return 5;
case 'I':
return 1;

} // end of romanVlaue

// given a Roman character this method converts it to an integer
// For example Given I returns 1, X returns 10, etc

return -999;
} // end of romanVlaue

// STUB ONLY ~ needs code and needs javadoc

public String arabicNumeralString (String sTest){
int t;
int ans=0;
/// To upper case method put here See lec 5/
// What about mixed case?! :-)
if (t < 0) {
System.out.println("\tArabicNumeral: sTest"+sTest+" is invalid Roman Numeral string");
return null;
else {
System.out.println("\tArabicNumeral: sTest"+sTest+" is valid Roman Numeral string");
char cAry[]=sTest.toCharArray();

for (int i=0;i<cAry.length;i++){

for (int i=0;i<cAry.length;i++) {

if(i<cAry.length-1) {
if(cAry[i] >= cAry[i+1]){
//add to running total
ans= ans + cAry[i];

ans= ans - cAry[i];
//sub to running total

/* //1. convert sTest to char array cAry[] -- see Lec 4
char cAry[] = sTest.toCharArray();
// else look ahead to determine if you add or sub the running total (ans)

// your code goes here...could call a private method or three...
//ans=9; // the hard-coded 9 is to allow it to compile...
return Integer.toString(ans);
} // end of arabicNumeralString

public String toString() {
return ("Arabic Numeral is using "+super.toString());
} // end of toString

} // end of ArabicNumeral
Campbell Ritchie
Posts: 56533
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question twice.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!