Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Inthis exercise we will create abasic application that allows aperson to convert between Jamaican and American currency. 1 . Create anew Java project entitledjavaCurrency. 2
Inthis exercise we will create abasic application that allows aperson to convert
between Jamaican and American currency.
Create anew Java project entitledjavaCurrency.
Create three packages: com.application.model,
com.application.controller and com.application.view.
In the com.application.model package create a class called CurrencyModel.
In the CurrencyModel class create two public functions: double
convertJMDToUSD This function accepts a double value representing
Jamaican Dollars and converts itto US Dollars and returns the converted
value and double convertUSDToJMD This function accepts a double value
representing US Dollars and converts itto Jamaican Dollars and returns the
converted valueThe formulas and exchange rate can be found online.
In the com.application.controller package create a class called
CurrencyController which contains one private variable of type CurrencyModel,
this class will also be your main class.
In the CurrencyController create apublic function convert which accepts two
String parameters: toConvertTo and value. Check if the string toConvertTo is
JMD or USD and call the corresponding model function You will need to
UPDATED BY CHRISTOPHER PANTHER FEB
convert the value to a double when calling the model functions The return type
is void.
In the com.application.view package create a class called CurrencyView.
Let your CurrencyView inherit from the JFrame class and the ActionListener
interface.
In the CurrencyView implement all unimplemented methods.
Create the following attributes in the CurrencyView class:
JLabel lblResult, lblValueLabel
JTextField txtValue
JRadioButton rdbToJMD, rdbToUSD
Button btnConvert, btnClear
JPanel panTop, panMiddle, panBottom
CurrencyController controller
In the CurrencyView create a private function called initializeComponents that
accepts nop arameters and has a return type of void. Use the primary constructor
for the Jlabels, JradioButtons, Jbutton and Jpanel. Use the default constructor for
the JTextField. Create a ButtonGroup variable and add the radio buttons to the
button group. The JPanels' should all be a grid layoutpanTop: columns row,
panMiddle: columns row, panBottom: columns row
In the CurrencyView create a private function called addComponentsToPanels that
accepts no parameters and has a return type of void. Add the components to the
correct panels as stated below:
panTop: lblValueLabel, txtValue, lblResult
panMiddle: rdbToJMD, rdbToUSD
panBottom: btnConvert, btnClear
In the CurrencyView create aprivate function called addPanelsToWindow that
accepts no parameters and has areturn type of void. Add each of the JPanels to
the frame in the following order: panTop, panMiddle, panBottom.
In the CurrencyView create aprivate function called setWindowProperties that
accepts no parameters and has a return type of void.
In the CurrencyView create aprivate function called registerListeners that accepts no
parameters and has a return type of void. Register the listeners for both the convert button and clear button.
In the CurrencyView class create aprimary constructor that accepts an instance of
a CurrencyController as its only parameter, set your local controller variable equal
to the passed parameter,then set the layout for your view to be a GridLayout with
rows and column. Finally call all functions created in steps in the same
order.
In the actionPerformed function inside the CurrencyView check if the source of the
event was the clear button, if it was, reset all the values to their default values.
In the actionPerformed function inside the CurrencyView check if the source of the
event was the convert button, if it was check which radio button is selected and then
call the convert function in the controller passing in the correct values.
Create apublic function updateResult which accepts one String parameter called
value, set the contents of the result label to be the passed value.
In the CurrencyController add a second private variable of type CurrencyView.
Update the CurrencyController function convert such that the result of the
conversion is passed to theCurrencyView function updateResult as a string.
Create a default Controller for the CurrencyController that initializes both the
model and view The view constructor should accept the current instance of the
controller as its argument
In the main function initialize the controller, and then run the program.
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