CSC2310 Assignment 3 25 points due 9/21/01 Dr. Harrison Fall 2001
This project will exercise your skills with loops and objects. Please write a program to convert between English units and S.I. Units. It comes in three parts. (hint, test each class after you write it rather than waiting to finish them all).
Part 1) Write a class that defines an object that takes strings of the form "number Units" to two strings "number" and "units" (e.g. It should take "2 oz" to "2" "oz" or "3lbs" to "3" "lbs"). The class will need to have a constructor (which can be almost empty), a method which when passed a string cuts it into two pieces (hint, use Stringbuffer or CharacterArray, String.trim and the Character isLetter and isDigit routines). There should be a method which returns the first string, one which returns the second string and one which returns a boolean that is false if there is no number in the initial string (and true if there is one). (These are a constructor and 4 public methods, you can write as many more private methods as you want).
Part 2) Write a class that defines an object that converts units. It should be constructed with a constant (for example 2.54 for inches and cm), and two strings (in this example
"in" and "cm"). It should have a method that returns a boolean which is true when the units match (i.e. units_match("in") returns true if it knows what to do with inches) and returns false if the units don't match. It needs a method that converts a supplied number (extra credit if you supply multiple versions with String, double, and float) and returns a double in the new units. There should also be a method that returns the new units as a string. This way you can write an output string like 1.00000000 cm. It should ignore the case on the string ("in" should match "In", "IN" and "iN").
|
constant |
English |
S.I. |
|---|---|---|
|
0.025400 |
in |
M |
|
0.028350 |
oz |
Kg |
|
0.453592 |
lbs |
Kg |
|
0.264145 |
gal |
Liter |
|
35.238500 |
Bushel |
Liter |
|
5.029210 |
Rod |
M |
The program should output the input string followed by its conversion as in:
1 Bushel is 35.2385 liter
(don't worry about the number of decimal places)
If it doesn't know how to convert it should say:
I can't convert 1 perch
(a perch is an very obscure unit of volume)
The sources for the programs should be printed and the sources and class files should be supplied on a disk. Please label your work.