Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are a car manufacturer assembling a new car model for the US market. Your speedometer supplier, a company in Italy, has shipped a bunch

You are a car manufacturer assembling a new car model for the US market. Your speedometer supplier, a company in Italy, has shipped a bunch of speedometers to use for the car. Speedometers measure and return the precise speed of the vehicle in km/h. The speedometers have a driver called Speedo that implements the following interface:

public interface SpeedInterface { float getSpeed(); }

The problem is that your digital display, controlled by the DisplayUnit class, is designed to read and display the speed in miles/hour. So you need to convert the reading from km/h to miles/h. The conversion formula is S(miles/h)=S(km/h)*0.62137. Can you use the FULL Adapter Pattern in order to allow this conversion without any change to Speedo and SpeedInterface, and with minimal change in DisplayUnit?

Specifically Implement the solution in Java, by updating and augmenting the starter implementation below. A Converter class is added for your convenience, to be used from within your adapter.

/**

* Interface for speedometer objects

*/

public interface SpeedInterface {

/**

* @return The speed of the vehicle in km/h

*/

float getSpeed();

}

/**

* A stub implementation.

* [Always returns 60 km/h]

* DO NOT CHANGE

*/

public class Speedo implements SpeedInterface {

public float getSpeed() {

return 60;

}

}

/**

* The Client Implementation

* Change as necessary

*/

public class DisplayUnit {

public static void main(String[] args) {

SpeedInterface t = new Speedo();

System.out.println("Current Speed: " + t.getSpeed() + " miles/h");

}

}

/**

* Speed converter for your convenience.

* NOT to be used within DisplayUnit

* @param The speed in km/h

* @return The speed in miles/h

*/

public class Converter {

public double fromKMToMiles(double sp){

return(sp*0.62137);

}

}

//ADD CLASSES AND INTERFACES AS APPROPRIATE

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

What is paper chromatography?

Answered: 1 week ago

Question

Explain the cost of capital.

Answered: 1 week ago

Question

Define capital structure.

Answered: 1 week ago