Answered step by step
Verified Expert Solution
Link Copied!

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.
1. Create anew Java project entitledjavaCurrency.
2. Create three packages: com.application.model,
com.application.controller and com.application.view.
3. In the com.application.model package create a class called CurrencyModel.
4. 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 value).The formulas and exchange rate can be found online.
5. 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.
6. 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 2022, FEB 112
convert the value to a double when calling the model functions). The return type
is void.
7. In the com.application.view package create a class called CurrencyView.
8. Let your CurrencyView inherit from the JFrame class and the ActionListener
interface.
9. In the CurrencyView implement all unimplemented methods.
10. 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
11. 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 layout(panTop: 3 columns 1 row,
panMiddle: 2 columns 1 row, panBottom: 2 columns 1 row).
12. 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
13. 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.
14. In the CurrencyView create aprivate function called setWindowProperties that
accepts no parameters and has a return type of void.
15. 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.
16. 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
3rows and 1 column. Finally call all functions created in steps 11-15 in the same
order.
17. 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.
18. 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.
19. Create apublic function updateResult which accepts one String parameter called
value, set the contents of the result label to be the passed value.
20. In the CurrencyController add a second private variable of type CurrencyView.
21. Update the CurrencyController function convert such that the result of the
conversion is passed to theCurrencyView function updateResult as a string.
22. 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).
23. 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

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

What is IUPAC system? Name organic compounds using IUPAC system.

Answered: 1 week ago

Question

What happens when carbonate and hydrogen react with carbonate?

Answered: 1 week ago