This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Currency Converter in Java

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
Please help me with this issue ?
Regards
Deepak
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please BeForthrightWhenCrossPostingToOtherSites
http://forums.oracle.com/forums/thread.jspa?threadID=1693488
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Darryl,Sorry for cross posting in other forums.I went out of my way to post in OTN forums.

 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    Campbell Ritchie
    Sheriff
    Posts: 48642
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 561
    Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ranchers,
    Please find the implementation below


    Best Regards
    Deepak Lal
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic