Results 1 to 3 of 3

Thread: ConvertCurrency

  1. #1
    Albert050 is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default ConvertCurrency

    Can anybody help me with Convert Currency by using GUI, I have the code that I work on but I have trouble working with GUI to show the result. The cod basically read from file and take number an convert it to other currency. Can you give idea how to do it?

    This is what I reached so far :




    -----------------------------------------------------------------------------------------------

    package cinverter;

    import java.util.*;
    import java.io.*;
    public class ConvertMoney extends javax.swing.JFrame {

    /** Creates new form ConvertMoney */
    public ConvertMoney() {
    initComponents();

    private void ConvertmoneyActionPerformed(java.awt.event.ActionE vent evt) {


    class CurrencyConverter{
    String Amount= CurrentAmount.getText();
    double i = Integer.parseInt(Amount);

    private HashMap<String, Double> Rates;
    private ArrayList<String> Currencies;

    public CurrencyConverter() {
    Rates = new HashMap<String, Double>(); //instantiate HashMap with key-value types defined
    Currencies = new ArrayList<String>(); // instantiate ArrayList with element type defined
    populateRates(); //populate HashMap with key-value pairs
    loadCurrencies(); // populate ArrayList with elements
    }

    private void populateRates() {
    Scanner SC=null;
    try{
    SC = new Scanner(new FileReader(new File("Rates.txt")));
    }catch(IOException e){
    System.err.println("File Error");
    System.exit(1);
    }
    while (SC.hasNextLine()){
    String[] S = SC.nextLine().split(" ",2); //parse input
    Rates.put(S[0], Double.parseDouble(S[1]));
    }
    }

    private void loadCurrencies(){
    HashSet<String> HSI = new HashSet<String>(Rates.keySet());//instantiate HashSet and load with Key element

    Iterator<String> it1 = HSI.iterator();
    while(it1.hasNext()){
    String s = it1.next();
    Currencies.add(s); // populste ArrayList with HSI elements
    }
    }

    public double convert(String FC, String TC, double amt){
    double result = amt/Rates.get(FC)*Rates.get(TC);
    return result;
    }

    public void showAll(){
    System.out.println("Rates Data: " + Rates);
    System.out.println("Currencies: " + Currencies);
    }
    }




    }

    private void CurrentAmountActionPerformed(java.awt.event.Action Event evt) {
    // TODO add your handling code here:
    }

    private void Exit1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

    System.exit(0);
    }

    /**
    * @param args the command line arguments
    */


    public static void main(String args[]) {
    /* Set the Nimbus look and feel */


    CurrencyConverter CC = new CurrencyConverter();
    CC.showAll();
    double amt = 50.55;
    System.out.println(amt + " USD = " + CC.convert("USD", "INR", amt) + " INR");
    }




    -------------------------------------------------------------------------------------------------------

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Albert050 is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default Re: ConvertCurrency

    Okay but no body want to help me, I saw many of them visit this topic but no one I think interested.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •