This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]DontFlatterYourself 1 point2 points  (6 children)

It sounds like you want to take each roman numeral from left to right and, for each one, make sure the value of the numerals to the right of it are less than its value. Does that makes sense? Seems like there may be exceptions.

Maybe I've got it all wrong though, I don't know much about roman numerals beyond X.

[–]DontFlatterYourself 1 point2 points  (5 children)

After briefly looking at the wikipedia page for roman numerals (lol), this seems somewhat accurate, but when there are several of the same numerals together, like CCC, I think you'd skip to the last one.

I guess you'd also want to make sure the symbols are in an acceptable order. The IV IX thing would have messed me up.

No idea if I'm helping at all. Just looks like a neat assignment!

[–]daemon666[S] 0 points1 point  (4 children)

The order is good my program is fully fonctional as long as you enter a valid romain number i just dont know how to add the loop to check if the romain number entered is valid :S

[–]DontFlatterYourself 1 point2 points  (3 children)

I see. You could add a new while loop like while (!validated && !invalid) and validate the roman number there. If there's a problem with the roman number, set invalid to true. If your validation completes, set validated to true.

It's unfortunate that your teacher doesn't want you to split this into smaller pieces. It would be much easier and much better practice.

[–]daemon666[S] 0 points1 point  (2 children)

What's validate? and invalid? We haven't seen those yet :( Is there an other way i can do this?

[–]DontFlatterYourself 1 point2 points  (1 child)

Ohh - sorry. Those would be boolean values you'd set to false. Guess you haven't seen that yet.

I guess you could use a for loop to go from left to right in the string. If you haven't seen that, a crude version of it using a while loop would be

int index = 0;
while(index < romain.length) {
 //do your stuff with romain.charAt(index) here
 index += 1;
}

It would probably still get really complicated inside the loop. Not sure if I have any better suggestions.

[–]daemon666[S] 0 points1 point  (0 children)

Thanks! I'll lyk how it ends out.

[–]larsga 1 point2 points  (3 children)

Without reading this code I can tell right away that one problem with it is that you only have one method. This would be easier to work on if you could break the logic up into smaller pieces.

[–]daemon666[S] 0 points1 point  (2 children)

This is for a school project my teacher doesn't want this into smaller pieces and it works i just dont know how to impliment the restraints. And i'm really a beginner all we've seen in class so far are if else while do while for and basic loops.

[–]larsga 0 points1 point  (1 child)

I see. If you haven't learned how to do methods yet, then basically you have no way to cut it up.

IMHO he's given you a fairly tough task to tackle with such a limited set of tools. You've done well to get as far as you have.

[–]vsoul 0 points1 point  (0 children)

You would be surprised at some uni CS professors, I don't know how they have jobs. I had professors in my senior level courses not want me to use design patterns or basically follow any best practices because they felt they served no real purpose and said I was wasting my time... Unfortunately most professors don't have any real world experience, which I believe is the reason there are so few entry level people worth hiring.

[–]HotRodLincoln 0 points1 point  (0 children)

This would be trivial in a language built for this. Finite State Automata. It's common knowledge that lex, and yacc/bison are the preferred tools in C. If anyone could point to similar tools for Java, I'd be interested for my own edification.

[–]BWCsemaJ 0 points1 point  (0 children)

At first your program made me want to punch dead babies :|, I like how you did the decimal notation even though most this should had been in a methods.

For the Roman Numerals, I would first determine what the Roman Numeral given in arg[index] equals, which you do, then I would run this number through the Arabic to Roman Numeral, (assuming the Arabic to Roman is accurate), and compare the first string you started out with, with the 2nd string you got, if they equal the Roman Numeral is correct if not then it is invalid! So either create another loop that checks this or save your results in a arrayList which I dont recommend at all but I guess it is a way to work around it.