Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write code 14 public class Distance 1 Enum of distance units public enum Distanceunit i KILOMETRES 19 MILES 20 22 25 Constants private static final

image text in transcribed write code
image text in transcribed
image text in transcribed
image text in transcribed
14 public class Distance 1 Enum of distance units public enum Distanceunit i KILOMETRES 19 MILES 20 22 25 Constants private static final double KHS PER_MILE = 1.689; private static final double MILES_PER_KM = 8.621; Instance variables private double value private Distancetinit distanceunit; 1 Constructors public Distance (double value) { this.value=value; 17 Default unit is km this.distanceunit = Distanceunit. KILOMETRES; 1 public Distance(double value, Distanceunit distanceunit) { this.value=value this.distanceUnit = distanceUnit: az 38 40 41 11thods: You should remove the comments and complete the method bodies for all the methods below Think that all these methods are in the class for a reason, So you should use them all DO NOT MODIFY the signature of these methods public double get value return this.value; WTYLU 3 45 47 48 51 52 53 $4 55 56 57 a58 159 public double getValue() { return this.value; ) public double getValue (Distanceunit unit) { // Add your own code here to indicate in which units you request the class to return the distance } public void setValue(double newalue) { this.value = newalue; // Add your own code here to set a new value (the DistanceUnit should not change, however) > puble DistanceUnit getDistanceUnito 1/ TODO Add your own code here to return the unit of this distance > public void changeDistanceunit (Distanceunit nostage unit) W To Add your own code here to set the unit of this Distance, and change the distance value accordingly. > 52 63 64 65 public static double convertToMiles (double kilometres) { 7/ 1000 Add your own code here to convert kilometres into miles. Use one of the constants provided public static double convertTokilometres (double silen) { W TO00 Add your own code here to convert miles into Kilometres. Use one of the constants provided public String tastring) 17 00 Add your own code here to display the contents of this Distance object 2 12 13 14 15 16 17- 18 19 20 21 22 in NNNNNN 1/ Constants! private static final double MILES_PER_KM = 0.621; private static final double DELTA = 0.001; Test public void testGetValue() { Distance a = new Distance(70.3); assertEquals(70.3, a.getValue(), DELTA); assertEquals(a.getDistanceUnit(), DistanceUnit.KILOMETRES); 3 public void testsetValue() { Distance a = new Distance(70.3); a.setValue(684.9); assertEquals(604.9, a.getValue(), DELTA); assertEquals(a.getDistanceUnit(), DistanceUnit.KILOMETRES); 1 29 se 31 32- 33 34 35 36 37 38 39 Test public void testConvertToMiles() { assertEquals(3 . MILES_PER_KM, Distance.convertToMiles(3), DELTA), } 42 43 public void testToString() { Distance a = new Distance(17); assertTrue(a.toString().contains(String.valueof(17))); } @Test public void testGetValueWithUnitMiles() { /* WTI AUTRES. Writable SH } @Test public void testsetValue() { Distance a = new Distance (70.3); a.setValue(604.9); assertEquals(604.9, a.getValue(), DELTA); assertEquals(a.getDistanceUnit(), DistanceUnit.KILOMETRES); 22 23 24 25 26 27 28 29 3e 31 32 33 34 35 36 37 38 39 Test public void testConvertToMiles() { assertEquals(3 * MILES_PER_KM, Distance.convertToMiles(3), DELTA); } I @Test public void testToString() { Distance a = new Distance(17); assert True(a.toString().contains (String.valueOf(17))); } 42 43 44 45 46 47 @Test public void testGetValueWithUnitMiles() { Distance a = new Distance(10, DistanceUnit.KILOMETRES); assertEquals(18 * MILES_PER_KM, a.getValue (DistanceUnit.MILES), DELTA); Distance b = new Distance (10, DistanceUnit.MILES); assertEquals(10, b.getValue (DistanceUnit.MILES), DELTA); 48 49 5e 52 52 ) 53 Writable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago