This question has always bothered me in a book I read a while ago and I can't find a proper solution. It's a program to convert a given number(integer) to roman numerals, for some reason I think I'm not doing this the most efficient way. Whenever code is repeated like this, there has to be something I missed. Loops aren't even covered yet in the book, yet this exercise is given. I've long finished the book, but I just wanted to know what I was doing wrong if loops weren't intended to be used, and my code looks bad enough as it is... here it is
There must be some other design I was overlooking, especially since this book is easy, including the exercises. This code is very ugly. Can anyone see what I'm overlooking in the design? Thanks.
This isn't the perfect response: About two weeks ago I read an article on extreme programming, unit testing, and object oriented design that was based on this very task (converting numbers to roman numerals). It might have been on extremeprogramming.org or JavaWorld.com or JUnit.org or who knows where. I think the article was more than 3 months old (leaning towards a year), but I don't really recall. And no, of course I don't remember the author. If I run across it (again), I'll post a link; or maybe someone else knows of the article - maybe someone over in the OO, Patterns, UML and Refactoring forum.
Thanks, I'll look around for it. I'm positive that my book has a serious problem in its exercises. It assigns this particular problem prematurely. I've been working at a solution, and there is no way this can be done using only if statements (which is as far as the book goes when assigned this exercise). It hasn't even gone into loops, Strings (in detail), anything. Only simple math functions and if and case statements. I guess it's ok, I want a real solution using any technique, just because this problem has been bugging me [ April 13, 2002: Message edited by: Peter Allen ]
Maybe they will give you this same exercise over and over, introducing each of the various programming elements, and let you them see how various programming element improve things. Eventually you could use loops, arrays, methods calls, and classes.
Thank you for the reply. Interestingly enough I found another solution from delphi code I saw, also some java code and I combined it. This does both functions, to roman numerals and also to arabic numbers. If anyone is interested, take a look
Joined: Dec 10, 2001
While I haven't really analyzed and tested the code, it looks like a much nicer design than the first time around. Well done. [ April 17, 2002: Message edited by: Dirk Schreckmann ]