Java Reference
In-Depth Information
{
/**
Constructs a converter that can
convert between two units.
@param aConversionFactor the factor by
which to multiply
to convert to the target unit
*/
public Converter(double aConversionFactor) {
. . . }
/**
Converts from a source measurement to
a target measurement.
@param fromMeasurement the measurement
@return the input value converted to
the target unit
*/
public double convertTo(double
fromMeasurement) { . . . }
/**
Converts from a target measurement to
a source measurement.
@param toMeasurement the target
measurement
@return the value whose conversion is
the target measurement
*/
public double convertFrom(double
toMeasurement) { . . . }
}
175
176
In your ConverterTester class, construct and test the following
Converter object:
final double MILE_TO_KM = 1.609;
Converter milesToMeters = new Converter(1000 *
MILE_TO_KM);
΢ Exercise P4.8. Write a class Square whose constructor receives the
length of the sides. Then supply methods to compute
ȗ The area and perimeter of the square
ȗ The length of the diagonal (use the Pythagorean theorem)
Search WWH ::




Custom Search