Converter Class Converter Class
home Student Projects no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. It does not describe an actual complete program. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; I have too many other projects of my own.

I do contract work for a living, which could include writing a program such as this. However, I don’t do people’s homework for them. That just robs them of an education.

You have my full permission to implement this project any way you please.

Whoever named the functions in Java for converting one type into another must have enjoyed memorising the French irregular verbs back in high school. There is very little regularity to the names. I propose writing a class CVT that is composed completely of static final wrapper methods for converting any of the 20 basic Java types into any of the others. The method names will be perfectly regular. Hopefully inlining will get rid of most of the overhead of using them.
Method Purpose
String CVT.toString(int) convert an int to a String
int CVT.toint(String) convert a String to an int
String CVT.toString(Integer) convert an Integer to a String
int CVT.toInteger(String) convert a String to an Integer
The wrapper methods could throw exceptions in some cases. The wrappers would take care of any trim()s needed to keep some of the parsers happy.

The conversion amanuensis has already done most of the work for you cataloging how you convert anything to anything. You simply have to modify its test driver to emit the source code for the CVT class. Bill Wilkinson posted some code similar to my proposed CVT class a year or so ago.


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] Spread the Net
You are visitor number 3,699.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/project/converter.html J:\mindprod\project\converter.html