Relates :
|
|
Relates :
|
|
Relates :
|
Name: rmT116609 Date: 03/24/2003 A DESCRIPTION OF THE REQUEST : ISO 4217, the standard on which this class is based, defines two currency codes -- one alphabetic and one numeric. The current version of the class implements only the alphabetic code and not the numeric. For instance: Currency curr = Currency.getInstance("USD"); System.out.println( "Currency Code = " + curr.getCurrencyCode() ); will print out: Currency Code = USD There is no method which will return the currency number. I suggest a method such as public int getCurrencyNumber(){} In this way the currency number can be returned. JUSTIFICATION : 1) The current class does not fully implement the ISO standard. 2) The numeric representation of the currency is used by banking facilities worldwide. 3) It is more efficient to use the numeric representation in comparisons. 4) The numeric representation of the currency may be used in "switch" constructs. EXPECTED VERSUS ACTUAL BEHAVIOR : Currency curr = Currency.getInstance("USD"); System.out.println( "Currency Code = " + curr.getCurrencyCode() ); System.out.println( "Currency Number = " + String.valueOf(curr.getCurrencyNumber()) ); results in Currency Code = USD Currency Number = 840 Not implemented. ---------- BEGIN SOURCE ---------- public class TestCurrency { public static void main( String args[] ) { Currency curr = Currency.getInstance("USD"); System.out.println( "Currency Code = " + curr.getCurrencyCode() ); System.out.println( "Currency Number = " + String.valueOf(curr.getCurrencyNumber()) ); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : package Test; import java.util.Locale; public class Currency { //Global constants //Global variables //Instance constants //Instance variables java.util.Currency curr = null; //Constructors public Currency( String currCode ) { curr = java.util.Currency.getInstance(currCode); } public Currency( Locale currLocale ) { curr = java.util.Currency.getInstance(currLocale); } //Methods public String getCurrencyCode() { return( curr.getCurrencyCode() ); } public int getCurrencyNumber() { String cCode = this.getCurrencyCode(); if( cCode.equals("USD") ) return(840); return(0); } public static void main( String args[] ) { try { Test.Currency curr = new Test.Currency("USD"); int cCode = curr.getCurrencyNumber(); System.out.println( String.valueOf(cCode) ); } catch(Exception e) { e.printStackTrace(); } } } when runs, results in: 840 which is the numeric representation of the currency "USD". (Review ID: 182955) ======================================================================
|