Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java GUI application to do currency conversions between US dollars, Euro

ID: 3907525 • Letter: W

Question

Write a Java GUI application to do currency conversions between US dollars, European euros, British pounds, Canadian dollars, and Japanese Yen. The GUI display should look something like the following:

Your program must meet the following requirements:

1.Do not use any of the GUI drag and drop editing capabilities of any development environment for this assignment.Do all the GUI layout work based on what you have learned in class.

2.The application must have a Label and TextField where the user inputs a value. These components must appear in the top part of the window as shown above.

3.The application must have a set of 5 RadioButtons which indicate the input currency of the amount to be converted. These 5 input currency buttons must be vertically aligned in the left part of the window as shown above.

4.The application must have a set of 5 RadioButtons which indicate the output currency to be converted to. These 5 output scale buttons must be vertically aligned and appear in the right part of the window as shown above.

5.The application must have a Label and TextField where the converted currency output appears. These components must appear in the bottom part of the window as shown above.

6.The application must have a TextArea within a ScrollPane to be used for error messages to the user. These components must appear in the center of the window.

7.The TextArea and the output TextField should NOT be editable.

8.Event handling must be setup so that selection of any input or output radio button causes an event which triggers the event handling code to determine which of 25 possible conversions is needed. Only selection of one of these 10 buttons causes an event that changes the GUI.

9.The output currency must be displayed to 2 digit accuracy.

10.If a button is clicked and there is a problem converting the input amount to a numeric value, the application must catch the exception and output an error message to the text area. It should also set the input textfield to the string “0”.

11.After any successful conversion, the text area for messages should be set to contain the empty string “”.

12.The application must accurately convert each of the 5 input currencies to each of the 5 output currencies.Only the selected conversion is displayed in the output textfield.

13.The application must detect when an invalid input amount has been entered. Any amount less than 0 is considered invalid. When an invalid amount has been detected, the application must output an error message to the text area, set the input text field to “0”, and set the output text field to the empty string “”. There should be no conversion done.

14.When the conversion selection changes due to clicking either an input or output scale button, the output area must change to show the new result.

15.HINT: For radio button events, use the isSelectedmethod on the radio buttons to find out which buttons are turned on!

16.The following are the conversion factors to use:

From|To

US Dollar

Euro

Pound

Can. Dollar

Yen

US Dollar

1

0.828

0.738

1.253

112.800

Euro

1.20773

1

0.8913

1.51329

136.2319

Pound

1.35501

1.12195

1

1.69783

152.8455

Can. Dollar

0.79808

0.66081

0.588986

1

90.0239

Yen

0.008865

0.00734

0.006543

0.011108

1

Make sure that you test all your conversion formulas and the error case handling!!!

Also make sure that you add comments to your program!

The project must compile in order to get any credit. Your Java source code must be loaded into a separate text file and uploaded into the drop box. Your project will not be graded without this. Your project must be loaded into a ZIP file and that single ZIP file must be uploaded into the drop box.

Rubric (50 pts)

GUI follows the requirements specified above. It includes 10 radio buttons, input and output scale designations, an obvious place for a user to enter a value, an obvious place where the converted value will be displayed, and an error display area. (20 pts)

Entering a non-numeric value as input causes an error message to be displayed in the text area and the application continues to run (5 pts)

Clicking on a radio button with no input number present causes an error message to be displayed in the text area and the application continues to run (5 pts)

Each time any radio button is clicked the new conversion is calculated and the output is updated. (5 pts)

If the input value is less than zero, an error message is displayed in the text area. The error is handled as described above. (5 pts)

The converted value is accurate for all conversions and is displayed to 2 digit accuracy. (5 pts)

Code follows style standards and code is commented. (5 pts)

From|To

US Dollar

Euro

Pound

Can. Dollar

Yen

US Dollar

1

0.828

0.738

1.253

112.800

Euro

1.20773

1

0.8913

1.51329

136.2319

Pound

1.35501

1.12195

1

1.69783

152.8455

Can. Dollar

0.79808

0.66081

0.588986

1

90.0239

Yen

0.008865

0.00734

0.006543

0.011108

1

Explanation / Answer

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JPanel;

import javax.swing.JTextField;

@SuppressWarnings("serial")

public class CurrencyConverterGBP extends JFrame

{

//three panels for the GUI

private JPanel inputPanel;

private JPanel resultPanel;

private JPanel menuPanel;

//labels that identify the fields

private JLabel promptLabel;

private JLabel resultLabel;

private JLabel selectLabel;

//menu for the list of currencies

private JMenu currencyMenu;

private JMenuBar currencyMenuBar;

//input field for user to enter currency

private JTextField inputField;

private JButton convertButton;

private JButton clearButton;

  

  

//initial values for each currency to 1 sterling

private double euros = 1.22;

private double japaneseYen = 152.07;

private double gambianDalasis = 42.53;

private double usDollars = 1.55;

private double canadianDollars = 1.70;

private double australianDollars = 2.50;

public CurrencyConverterGBP() //constructor

{

super();

this.setSize(400, 300); //set size of the window

this.setLayout(new GridLayout(3, 1)); //split the grid with panels

this.setTitle("Currency Converter"); //set window title

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //This will close the window

  

this.selectLabel = new JLabel("Select a currency to convert to: ", JLabel.RIGHT);

this.resultLabel = new JLabel(" ", JLabel.CENTER);

this.currencyMenu = new JMenu("(Click me to select a currency)"); //create a menu of currencies

JMenuItem Euros = new JMenuItem("Euros"); //store the string Euros as a menu item

Euros.addActionListener(new java.awt.event.ActionListener() //add a listener to this item

{

public void actionPerformed(java.awt.event.ActionEvent evt) //listen for event

{

menuChanged(evt);

}

});

this.currencyMenu.add(Euros);

JMenuItem JapaneseYen = new JMenuItem("Japanese Yen"); //store the string Japanese Yen as a menu item

JapaneseYen.addActionListener(new java.awt.event.ActionListener() //add a listener to this item

{

public void actionPerformed(java.awt.event.ActionEvent evt)

{

menuChanged(evt);

}

});

this.currencyMenu.add(JapaneseYen);

  

JMenuItem GambianDalasis = new JMenuItem("Gambian Dalasis"); //store the string russian rubles as a menu item

GambianDalasis.addActionListener(new java.awt.event.ActionListener() //add a listener to this item

{

public void actionPerformed(java.awt.event.ActionEvent evt)

{

menuChanged(evt);

}

});

this.currencyMenu.add(GambianDalasis);

  

  

JMenuItem CD = new JMenuItem("Canadian Dollars"); //store the string Canadian Dollars as a menu item

CD.addActionListener(new java.awt.event.ActionListener() //add a listener to this item

{

public void actionPerformed(java.awt.event.ActionEvent evt)

{

menuChanged(evt);

}

});

this.currencyMenu.add(CD);

  

JMenuItem USD = new JMenuItem("US Dollars"); //store the string US Dollars as a menu item

USD.addActionListener(new java.awt.event.ActionListener() //add a listener to this item

{

public void actionPerformed(java.awt.event.ActionEvent evt)

{

menuChanged(evt);

}

});

this.currencyMenu.add(USD);

currencyMenuBar = new JMenuBar(); //initialise a new menubar and add it to the currency menu

currencyMenuBar.add(currencyMenu);

this.menuPanel = new JPanel();

this.menuPanel.add(this.selectLabel);

this.menuPanel.add(this.currencyMenuBar);

this.add(this.menuPanel);

this.promptLabel = new JLabel("(Click me to select a currency) ", JLabel.RIGHT);

this.resultLabel = new JLabel(" ", JLabel.CENTER);

this.inputField = new JTextField("", 12);

//this.amountField.setEditable(false); //need help with this part

this.convertButton = new JButton("Click Me");

convertButton.addActionListener(new java.awt.event.ActionListener()

{

public void actionPerformed(java.awt.event.ActionEvent evt)

{

buttonclicked(evt);

}

});

this.inputPanel = new JPanel();

this.inputPanel.add(this.promptLabel);

this.inputPanel.add(this.inputField);

this.inputPanel.add(this.convertButton);

  

this.add(this.inputPanel);

this.resultPanel = new JPanel();

this.resultPanel.add(this.resultLabel);

this.add(this.resultPanel);

}

/*

* change the state of the menu bar depending on the selected currency

*/

public void menuChanged(ActionEvent e)

{

if (e.getActionCommand().equals("Euros"))

{

currencyMenu.setText("Euros");

}

if (e.getActionCommand().equals("Japanese Yen")) {

currencyMenu.setText("Japanese Yen");

}

if (e.getActionCommand().equals("Gambian Dalasis")) {

currencyMenu.setText("Gambian Dalasis");

}

if (e.getActionCommand().equals("Australian Dollars")) {

currencyMenu.setText("Australian Dollars");

}

  

if (e.getActionCommand().equals("Canadian Dollars")) {

currencyMenu.setText("Canadian Dollars");

}

if (e.getActionCommand().equals("US Dollars")) {

currencyMenu.setText("US Dollars");

}

}

/*

* Events listeners for goButton

* when the goButton is clicked it should return the user's initial value

* plus the converted amount and some predefined strings.

*/

public void buttonclicked(ActionEvent evt)

{

if(currencyMenu.getText().equals("Euros"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + EurosToSterling() + " Euros.");

}

  

  

if(currencyMenu.getText().equals("Japanese Yen"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + JapaneseYenToSterling() + " Japanese Yen.");

}

  

  

if(currencyMenu.getText().equals("Gambia Dalasis"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + GambianDalasisToSterling() + "Gambian Dalasis.");

}

  

  

  

if(currencyMenu.getText().equals("Australian Dollars"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + AustralianDollarsToSterling() + " Australian Dollars.");

}

  

  

if(currencyMenu.getText().equals("Canadian Dollars"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + CanadianDollarsToSterling() + " Canadian Dollars.");

}

  

  

if(currencyMenu.getText().equals("US Dollars"))

{

resultLabel.setText(inputField.getText() + " in sterling is " + USDollarsToSterling() + " US Dollars.");

}

}

/*

* Functions for converting currencies

* get the user entry from inputField, convert it to a

* double and multiply it by the rate of a particular

* currency to a sterling.

*/

private String CanadianDollarsToSterling() {

// TODO Auto-generated method stub

return null;

}

private String AustralianDollarsToSterling() {

// TODO Auto-generated method stub

return null;

}

@SuppressWarnings("unused")

private String CanadianDollars() {

// TODO Auto-generated method stub

return "";

}

//calculate the rate for euros

double EurosToSterling()

{

double calcTotal = Double.parseDouble(inputField.getText()) * euros;

return calcTotal;

}

//calculate the conversion rate for japanese yen

double JapaneseYenToSterling()

{

double calcTotal = Double.parseDouble(inputField.getText()) * japaneseYen;

return calcTotal;

}

//calculate the rate for russian rubles

double GambianDalasisToSterling()

{

double calcTotal = Double.parseDouble(inputField.getText()) * gambianDalasis;

return calcTotal;

}

//calculate the rate for us dollars

double USDollarsToSterling()

{

double calcTotal = Double.parseDouble(inputField.getText()) * usDollars;

return calcTotal;

}

/*

* main method to initialise CurrencyConverterWin

*/

public static void main(String[] args)

{

CurrencyConverter CurCon = new CurrencyConverter();

CurCon.setVisible(true);

}

  

public JButton getclearButton() {

return clearButton;

}

public void seclearButton(JButton convertButton) {

this.convertButton = convertButton;

}

  

public JButton getConvertButton() {

return convertButton;

}

public void setConvertButton(JButton convertButton) {

this.convertButton = convertButton;

}

public JButton getClearButton() {

return clearButton;

}

public void setClearButton(JButton clearButton) {

this.clearButton = clearButton;

}

public double getCanadianDollars() {

return canadianDollars;

}

public void setCanadianDollars(double canadianDollars) {

this.canadianDollars = canadianDollars;

}

public double getAustralianDollars() {

return australianDollars;

}

public void setAustralianDollars(double australianDollars) {

this.australianDollars = australianDollars;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote