• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

US/Metric Conversion

 
C. Alan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll admit right off that this is for an assignment, so please, no code samples. I just need a little help in understanding what my professor is trying to have us accomplish, because even though I know what we are going to do, the framework provided isn't making sense.

The package only consists of two classes, a unit class, and a conversion class. The unit class is really simple, and I understand what is happening with that.


The conversion code is where I get mystified, not the algortithms for the conversion, but accessing the correct data to do the conversion. In the constructor, we were given this:

The part I am having trouble understanding is how I access the correct instance of unit to retrieve the correct conversion values...

Thanks.

[ January 22, 2005: Message edited by: C. Alan ]
[ January 22, 2005: Message edited by: C. Alan ]
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah.. but what is it that you need to do?
basically, you probably need to access one or more instances of
Unit class in side Conversion.
You keep all those instances in an array called units[].
so - units[0] is the first Unit instance in the array, units[1] is
the second, and so on.
So, if you have a method named getWhatever() in your Unit class, and you
need to call it, you need to do something like this:



?
 
C. Alan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair enough... let's try a more clear question.

For example, I want to convert 1 inch into centimeters. The first step is to convert it to meters (common unit). Then next conversion would be to convert to centimeters.

In our conversionTest, we will pass a string to Conversion as follows:

Conversion has a method:

I'm starting to get a glimmer of understanding here..Am I making a correct assumption that based on category and measure, the correct Unit will be returned, allowing me to get the necessary conversion??... what am I returning as a value though?

Sorry if my question is vague... I know what we are trying to do, but with the little bit of framework given, I am not understanding the implementation.
 
C. Alan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh..I figured it out. I'm sure my instructor has a much more elegant solution, but as long as it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic