Design and implement Java program as follows:

1) Implement converter class hierarchy as follows:

a. Converter class which includes:

  • Private attribute for input of data type double
  • Default constructor with no parameter which sets input to Double.NaN [Not a Number]
  • Overloaded constructor with input for parameter
  • Method convert() which returns input value

b. TemperatureConverter class which is a child of Converter and includes:

  • Constructors which call parent constructors
  • Overridden convert() method to convert input (Fahrenheit temperature) to Celsius and returns the value. If the instance has no input value or not a number, it should return Double.NaN
  • Use the following formula for conversion: C = ((F-32) * 5)/9

c. DistanceConverter class which is a child of Converter and includes:

  • Constructors which call parent constructors
  • Overridden convert() method to convert input (distance in miles) to distance in kilometers and returns the value. If the instance has no input value or not a number, it should return Double.NaN

d. Use the following formula for conversion: KM = M * 1.609.

2) Do not use javax.swing.SwingUtilities in this program.

3) Implement GUIConverter class using JFrame and JPanel as follows

a. The window should be centered in the computer screen. [Hint: frame.setLocationRelativeTo(null);]

b. GUI will have 3 buttons: Distance, Temperature, and Exit that generate prompts. see image.

c. When user clicks Exit, the program will terminate.

d. When user clicks Distance, an input dialog will pop up where user can type value and click OK. see image.

e. Once user clicks OK, message dialog will pop up. see image.

f. After review of the result, the OK is clicked the program returns to the original window. see image.

g. When user clicks on Temperature button, an input dialog will pop up to input value and then when clicks OK, the message dialog with pop up with converted result: see image.

h. The format for the windows should be appropriately sized. As a guideline for the window the three buttons should all be of the same dimension surrounded by not more than 1/4 or 1/2 inch of space. In this case, the two conversion buttons should be on one line and the Exit on another. All the buttons should be surrounded by not more than an inch of space.

4) There is a main () method at the end of the program.

  • The method begins with instantiation of the Converter class.
  • A Interface is displayed either in this method or called by another method.
  • The Interface will consist of the two options [Temperature and Distance] and an exit button. [See above illustration].
  • The main () should be considered as a driver, that is, only the minimum number of code lines are in it. Most of the coding is done in methods that are outside of the main () method.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.