
-----------------------------------
uberwalla
Fri Feb 22, 2008 9:38 pm

Roman Numeral Converter Problem
-----------------------------------
Hey there thanks to those that have helped me through some of this with commands I didn't know. Trying to move into java from extensive javaSCRIPT is hard. A lot of different forms.

Anyways this is what i have so far:


import java.util.Scanner;

public class Assignment05 {	
	public static void main (String 

The code compiles fine but when I run it and enter a number i get the error:


Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 51
            at Assignment05.main(Assignment05.java:70)


any idea what i can do to fix this?

-----------------------------------
OneOffDriveByPoster
Fri Feb 22, 2008 9:44 pm

Re: Roman Numeral Converter Problem
-----------------------------------
                roman += all[length - i - 1][yearStr.charAt(i)];yearStr.charAt(i) returns a char.  '3' == 51.  You need use Integer.toString() or something like yearStr.charAt(i) - '0'.

-----------------------------------
uberwalla
Fri Feb 22, 2008 9:52 pm

Re: Roman Numeral Converter Problem
-----------------------------------
ok must ask how do i use the Integer.toString to my charAt? i tried using it like:

yearStr.charAt(Integer.toString(i))

but i got an error.

i am quite lost :(

-----------------------------------
OneOffDriveByPoster
Fri Feb 22, 2008 10:09 pm

Re: Roman Numeral Converter Problem
-----------------------------------
Try Integer.toString(yearStr.substring(i, i + 1)).

-----------------------------------
uberwalla
Fri Feb 22, 2008 10:16 pm

Re: Roman Numeral Converter Problem
-----------------------------------
i have no idea what this means: (its what i get using substring)


Assignment05.java:70: cannot find symbol
symbol  : method toString(java.lang.String)
location: class java.lang.Integer
                roman += all

-----------------------------------
OneOffDriveByPoster
Fri Feb 22, 2008 10:21 pm

Re: Roman Numeral Converter Problem
-----------------------------------
ugh, my fault:  Integer.parseInt instead.

-----------------------------------
uberwalla
Fri Feb 22, 2008 10:27 pm

Re: Roman Numeral Converter Problem
-----------------------------------
thanks a lot man. i actually found another way around this. 


import java.util.Scanner;

public class Assignment05 {	
	public static void main (String 

thanks for all your help

-----------------------------------
richcash
Sat Feb 23, 2008 11:42 pm

Re: Roman Numeral Converter Problem
-----------------------------------
If you have time/interest, try to shorten your program and significantly reduce the memory your program uses. You do not need to store all of those values in those arrays. Use some recursion (and math). And you also don't need to do the costly conversion of integer to string.

-----------------------------------
uberwalla
Sun Feb 24, 2008 11:49 am

Re: Roman Numeral Converter Problem
-----------------------------------
well i am still relatively new to java so i do not know how to easily reduce the program. i mostly know some of the commands from c/c++ and javascript, because they are relatively close. but java is still weird to me in how you have to format the code and such.
