The project will be submitted electronically through WebCT. Zip up your entire project folder for submission. (Right click on the project folder, follow the Send To link and select Compressed (zipped) Folder.) Once the compression process is done, you will have a zipped file with the same name as your project folder and an extension of .zip. This zipped file will be uploaded to the WebCT system during project submission. The project folder should include the following files:
You have been asked to write a program to construct and manipulate Length objects that can handle any of the following units: meters, inches, feet, yards, miles. In addition to modifying the methods as needed from Project 1, you will include methods for returning the number of meters, for adding two Length objects, and testing whether two Length objects are approximately equal.
Constants:
The following constants should be included in the Length class before the instance fields. These constants should be used by your methods. Points will be taken off if you use the numbers in your methods instead of the named constants.public static final double INCHES_PER_YARD = 36; public static final double FEET_PER_YARD = 3; public static final double METERS_PER_YARD = 0.9144; public static final double YARDS_PER_MILE = 1760; public static final double EPSILON = 0.000001;
Instance fields:
The instance fields are the same as for Project 1.
Constructors:
The constructor is the same as for Project 1.
Methods:
Three methods will be added, and the behavior of some methods will be changed.
The following methods should be added. The comments contain some hints.
/* getMeters returns the length in meters.
This should be implemented to calculate the appropriate conversion
based on the value of myUnit, e.g.,
if ( myUnit.equals("yards") )
meters = myNumber * METERS_PER_YARD;
If myUnit cannot be recognized, assume the unit is meters.
*/
public double getMeters( )
/* add returns a Length that is the sum of two Lengths, e.g.,
if length1 and length2 are two Length objects, then
length1.add(length2) will return a new Length object.
This can be implemented by using the getMeters method,
e.g., this.getMeters() + other.getMeters(), then returning
new Length(sum, "meters")
*/
public Length add(Length other)
/* aboutEqual returns true if the two lengths are within EPSILON
meters of each other.
First, get this.getMeters() and other.getMeters(). Then, return
true if they are close to each other (within EPSILON).
*/
public boolean aboutEqual(Length other)
The getInches, getFeet, getYards, and getMiles methods should be modified. First get the value of the getMeters method, e.g., this.getMeters(), then convert the number of meters to the desired unit using the named constants, and finally return that value.