Design and implement a class LinearMeasure that represents a linear measurement in either yards, feet, inches, meters, centimeters, or millimeters. Use an enumeration to represent these units of...


Design and implement a class LinearMeasure that represents a linear measurement in either yards, feet, inches, meters, centimeters, or millimeters. Use an enumeration to represent these units of measure. Define a constructor that has two parameters. One parameter represents the value of the measurement, and the other is a string that names the unit of measure. The case of the letters in this string should be irrelevant. Define methods that convert any measurement to any given unit. Each of these conversions should be performed by two methods: One should change the measure and units of the receiving object and return a reference to it; the other should not change the receiving object but simply return the value of the new measure as a real number. For example, statements such as


LinearMeasure length = new LinearMeasure(8.5, "yards");


System.out.println(length + " is " + length.inMeters() + " meters.");


System.out.println(length + ".");


System.out.println(length + " is " + length.toMeters() + ".");


System.out.println(length + ".");


should produce the following output:


8.5 yards is 7.7724 meters.


8.5 yards.


8.5 yards is 7.7724 meters.


7.7724 meters.


Demonstrate your class by writing an appropriate client.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here