Question
There is only one java file for all the coding of this assignment allowed. Must be designed under the following: package ConverterGui; public class ConverterGui
There is only one java file for all the coding of this assignment allowed.
Must be designed under the following:
package ConverterGui;
public class ConverterGui {
and then as requested:
Designand implementJava programas follows:
1)Implementconverter classhierarchy as follows:
a.Converter class which includes:
- Private attribute forinputof 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
- The window should be centered in the computer screen. [Hint: frame.setLocationRelativeTo(null);]
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
- GUI will have 3 buttons: Distance, Temperature, and Exit that generate prompts.
- When user clicks Exit, the program will terminate.
- When user clicks Distance, an input dialog will pop up where user can type value and click OK.
- Once user clicks OK, message dialog will pop up.
- After review of the result, the OK is clicked the program returns to the original window.
- 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:
- 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 or 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.
SUGGESTIONS:
- For the input dialog you can use JOptionPane.showInputDialog.
- The ActionListener for each Converter button should create the appropriate Converter child instance, set the input, and call its convert () method.
- For the pop up with converted value you can use JOptionPane.showMessageDialog
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started