aspose file tools*
The moose likes Java in General and the fly likes Currency Converter in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Currency Converter in Java" Watch "Currency Converter in Java" New topic
Author

Currency Converter in Java

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers,
We are designing a java based application for currency conversion where the currency name and currency decode values are stored in Currency Table,The foreign exchange rates are stored in Foreign_exchange rates table.I have to go ahead and implement this,can you please suggest me some ideas as to how should i go about implementing this.This scenario is in Trading based real time application where the foreign exchange rates are changing every now and then,so my question is how will i get the latest value which will be in sync and calculate the "correct conversion rate".Please advice..What datastructure should i use for implementing this.


The above values will be got from a foreign exchange feeder system,how will i ensure the values are in sync always?Hope my question is understood now.

Regards,
Deepak.


When The Going Gets Tougher,The Tougher gets Going
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers,
Please help me with this issue ?
Regards
Deepak
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

First of all remember that PatienceIsAVirtue. We are all volunteers that do this in our free time.

I use the java.util.Currency class and create a wrapper that contains the conversion values.
A simple Map would be sufficient. Or in a multi-threaded environment a ConcurrentMap.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Wouter Oet wrote:First of all remember that PatienceIsAVirtue. We are all volunteers that do this in our free time.

I use the java.util.Currency class and create a wrapper that contains the conversion values.
A simple Map would be sufficient. Or in a multi-threaded environment a ConcurrentMap.


Thanks for your time and reply,but i do not know as to how should i implement using the Currency class.How should i write a wrapper for conversion values either.Could you advice me on this.?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

It seems that you might be getting the data from some database tables. In that case your first attempt at design should be to create classes which mirror those tables. Each column in a table should be implemented as a member of the class.

Why don't you start out with, say, your Currency table? Post the contents of the table (I mean the list of columns, not the data in the table) and a class you have written based on that. Then we can discuss it.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Paul Clapham wrote:It seems that you might be getting the data from some database tables. In that case your first attempt at design should be to create classes which mirror those tables. Each column in a table should be implemented as a member of the class.

Why don't you start out with, say, your Currency table? Post the contents of the table (I mean the list of columns, not the data in the table) and a class you have written based on that. Then we can discuss it.



@Paul,Please find the classes below


The above 2 classes mirror my database tables...Please let me know if design is correct or not now..how should i proceed now.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Well, that answers your original question, which was (to remind everyone reading this thread):
Deepak Lal wrote:Please advice..What datastructure should i use for implementing this.

So yes, that's a reasonable data structure to use. Do you have another specific question? "How should I proceed now" isn't a specific question which can reasonably be answered on a forum, except by saying "Next you should decide what you want to do with those data structures."
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Paul Clapham wrote:Well, that answers your original question, which was (to remind everyone reading this thread):
Deepak Lal wrote:Please advice..What datastructure should i use for implementing this.

So yes, that's a reasonable data structure to use. Do you have another specific question? "How should I proceed now" isn't a specific question which can reasonably be answered on a forum, except by saying "Next you should decide what you want to do with those data structures."


@Paul,I have written the data structure,so my next question is how should i implement the currency converter which i have been discussing in this thread.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Deepak Lal wrote:@Paul,I have written the data structure,so my next question is how should i implement the currency converter which i have been discussing in this thread.


Well, first you should decide what things you want it to do. Then you write code which does those things. So how about if you get started with that? List the things you want it to do.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Paul Clapham wrote:
Deepak Lal wrote:@Paul,I have written the data structure,so my next question is how should i implement the currency converter which i have been discussing in this thread.


Well, first you should decide what things you want it to do. Then you write code which does those things. So how about if you get started with that? List the things you want it to do.


As i mentioned it should convert the currency rates(as it has been discussed in the orginal post also.)suppose i have 1 USD equivalent to 46 INR hence if i enter 12 USD it should give me the quivalent INR and point ot remember here is that INR rate is changing per sec/nanosec since im working in a real time Trade based Java application.so this is what im supposed to do,hope you have got my understanding now.Could you please tell me how should my implementation code be for this.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Deepak Lal wrote: . . . Could you please tell me how should my implementation code be for this.
No. You may however be able to pay one of us to write it for you.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Please BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1693488


luck, db
There are no new questions, but there may be new answers.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

@Darryl,Sorry for cross posting in other forums.I went out of my way to post in OTN forums.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Deepak Lal wrote:suppose i have 1 USD equivalent to 46 INR hence if i enter 12 USD it should give me the quivalent INR and point ot remember here is that INR rate is changing per sec/nanosec since im working in a real time Trade based Java application.so this is what im supposed to do,hope you have got my understanding now.Could you please tell me how should my implementation code be for this.


First you should figure out what your requirements are. Write them down in a list. Then implement them one at a time.

What you have posted there isn't a requirement. It's a mish-mash of two separate requirements, namely

  • The code should calculate the number of INR corresponding to a given number of USD.
  • The code should use the most recent available conversion rates.


  • Then once you have a list of requirements, you can focus on them separately. You can see from what you posted there that you can't think about doing an ordinary currency conversion because you started raving about nanoseconds. Just do one thing at a time.

    And by the way, an example isn't a requirement. Working from examples is likely to lead to problems because the examples usually don't cover the whole requirement.
    Soumyajit Hazra
    Ranch Hand

    Joined: Jun 26, 2007
    Posts: 136
    INR rate is changing per sec/nanosec since im working in a real time Trade based Java application
    Not sure but I think the exchange rate changed daily basis not every second. Please rectify me if I am incorrect.


    Java Programmer | SCJP 1.5 | SCWCD 1.4
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 40052
        
      28
    It is not usual to detect changes by the nanosecond, but rates and share prices etc. can change from second to second.
    Deepak Lal
    Ranch Hand

    Joined: Jul 01, 2008
    Posts: 507

    Ranchers,
    Please find the implementation below


    Best Regards
    Deepak Lal
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Currency Converter in Java