Question
please write code in java language and do not add any break, continue or goto statements
Write a program with a graphical interface that allows the user to convert an amount of money between U.S. dollars (USD), eur
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

Please find the code below:

package graphichal;

import java.awt.Color;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class CurrencyConverter{

public static void main(String[] args){ //main class

final JFrame f=new JFrame();

//ADD TEXT FIELDS

final JTextField currencyInput=new JTextField(20);

final JLabel output = new JLabel();

JButton update=new JButton("Convert");

// SET LAYOUT TO GRID

f.setLayout(new GridLayout(4, 3));

//ADD COMBO BOXES

final JComboBox<String> jc=new JComboBox<String>();

jc.addItem("EUR");

jc.addItem("USD");

jc.addItem("GBP");

final JComboBox<String> jc2=new JComboBox<String>();

jc2.addItem("EUR");

jc2.addItem("USD");

jc2.addItem("GBP");

f.add(new JLabel("SELECT FROM CURRENCY"));

f.add(currencyInput);

f.add(new JLabel("SELECT TO CURRENCY"));

f.add(jc);

f.add(new JLabel("ENTER VALUE IN THE TEXT BOX"));

f.add(jc2);

final JLabel error = new JLabel("");

final JLabel error1 = new JLabel("");

error.setForeground(Color.red);

error1.setForeground(Color.red);

f.add(error);

f.add(update);

f.add(error1);

final JLabel resultMsg =new JLabel("");

f.add(resultMsg);

f.add(output);

update.setBounds(150, 300,200, 20);

f.setVisible(true);

f.pack();

update.addActionListener(new ActionListener(){ //listener for button getResult

public void actionPerformed(ActionEvent e){

//DO CALCULATIONS BASED ON INPUT AND OUTPUT

try{

resultMsg.setText("CONVERTED VALUE IS ");

error.setText("");

error1.setText("");

double fromData = Double.parseDouble(currencyInput.getText());

String from = jc.getSelectedItem().toString();

String to = jc2.getSelectedItem().toString();

if(from.equalsIgnoreCase("EUR") && to.equalsIgnoreCase("USD")){

double result =fromData*1.42;

output.setText(result+" "+to);

}else if(from.equalsIgnoreCase("EUR") && to.equalsIgnoreCase("GBP")){

double result =fromData/1.13;

output.setText(result+" "+to);

}else if(from.equalsIgnoreCase("USD") && to.equalsIgnoreCase("EUR")){

double result =fromData/1.42;

output.setText(result+" "+to);

}else if(from.equalsIgnoreCase("USD") && to.equalsIgnoreCase("GBP")){

double result =fromData/1.64;

output.setText(result+" "+to);

}else if(from.equalsIgnoreCase("GBP") && to.equalsIgnoreCase("USD")){

double result =fromData*1.64;

output.setText(result+" "+to);

}else if(from.equalsIgnoreCase("GBP") && to.equalsIgnoreCase("EUR")){

double result =fromData*1.13;

output.setText(result+" "+to);

}else{

error1.setText("FROM AND TO SHOULD BE DIFFERENT");

error.setText("FROM AND TO SHOULD BE DIFFERENT");

resultMsg.setText("");

output.setText("");

}

}catch(Exception ex){

resultMsg.setText("");

System.out.println(ex);

}

}

});

}

}

output:

ahal SELECT FROM CURRENCY SELECT TO CURRENCY 1 ENTER VALUE IN THE TEXT BOX EUR EUR FROM AND TO SHOULD BE DIFFERENT FROM AND T

Call the main program Converter.java. You will need another class for the frame. X FSELECT FROM CURRENCY 1 SELECT TO CURRENCY

Add a comment
Know the answer?
Add Answer to:
please write code in java language and do not add any break, continue or goto statements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT