File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Arabic Numeral Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arabic Numeral Program" Watch "Arabic Numeral Program" New topic

Arabic Numeral Program

Frank White

Joined: Mar 01, 2008
Posts: 7
I have written a program to take roman numerals in, and parse them into arabic integers. The problem I'm having is parameters with IIIII=5 and not V. Can anyone help?

public class ArabicNumeral extends NumberStringEva {

} // end of constructor

private int romanValue(char cAry){

switch (cAry){
case 'M':
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
[ March 02, 2008: Message edited by: Frankhank White ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33127

Can you show what you have so far?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Frank White

Joined: Mar 01, 2008
Posts: 7
Jeanne, I posted the cod that I have. Yesterday it kept telling me I have invalid character when posting. It told me to Change all "<" to &B or something but it wouldn't let me post until I took the code out. Sorry.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Originally posted by Frankhank White:
The problem I'm having is parameters with IIIII=5 and not V.
I don't get this either. Are you saying when you input "IIIII" you should get "5" but you actually get "V"? Surely not. Maybe you could try again. Tell us what your inputs are, what your outputs should be, and what you are getting instead.
Frank White

Joined: Mar 01, 2008
Posts: 7
Thank you for responding, and sorry for not being more clear. This is my first time.

The program is supposed to input (from the command prompt) integers and the program is to change them from arabic to roman numeral. That part I have completed. Also, the program (Part 2) is to be expanded to input roman numerals and output arabic numerals. This is the part I'm having trouble with. I got it to work, but if you input IIIII you get 5, when V=5. IIIII is outside the params it is not a roman numeral.

Thank you Frank
I agree. Here's the link:
subject: Arabic Numeral Program
jQuery in Action, 3rd edition