Question: Implement the interface ScaleConverter, shown below, and test your implementations. public interface ScaleConverter{ public double convertTemperature(double tempIn); public double convertDistance(double distanceIn); public double convertWeight(double weightIn);
Implement the interface ScaleConverter, shown below, and test your implementations.
public interface ScaleConverter{ public double convertTemperature(double tempIn); public double convertDistance(double distanceIn); public double convertWeight(double weightIn); }
Part A, 60 points
Implement the interface with two classes, EnglishToMetricConverter and MetricToEnglishConverter. The conversion formulas from English units to metric units are as follows:
temperature in Celsius = (temperature in Fahrenheit 32) * 5/9 distance in KM = distance in miles * 1.609 weight in KG = weight in pounds/2.2
These formulas should be easy to reverse for metric to English conversion, but when you write the F to C conversion code recall the rules of operator precedence.
Part B, 40 points
Write JUnit tests to verify that your implementation of the EnglishToMetricConverter is correct. In a production application, of course, you would also have to test MetricToEnglishConverter, but you do not need to do so for this exam.
package fall2016cs2010final;
import static org.junit.Assert.*;
import org.junit.Test;
public class EnglishToMetricConverterTester {
@Test public void testFreezingConversion() { EnglishToMetricConverter e = new EnglishToMetricConverter(); final double freezingF = 32.0; final double freezingC = 0.0; assertEquals(e.convertTemperature(freezingF), freezingC, 0.0001); }
@Test public void testBoilingConversion() { EnglishToMetricConverter e = new EnglishToMetricConverter(); final double boilingF = 212.0; final double boilingC = 100.0; assertEquals(e.convertTemperature(boilingF), boilingC, 0.0001); } /* add another test to verify that your converter shows the value -40 C for the input -40 F*/
/* add at least two tests to verify that miles to KM conversion is correct. Test several values, but one of them should test with the input value 1 mile. */ /* add at least two tests to verify that pounds to KG conversion is correct. test several values, but one of them should use the input value 2.2 pounds. */
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
