Solved

Existing constant definitions for $, €, etc

Posted on 2012-04-04
5
232 Views
Last Modified: 2012-04-05
Are there existing constant definitions for symbols like $ and €?
such that I could refer to them like:
String myString = SomeClass.DOLLAR_SIGN + myDouble;

Open in new window

Either in Java proper, or another API like Apache Commons.
0
Comment
Question by:allelopath
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:HomerTNachoCheese
ID: 37807443
Maybe all you need to do is something similar to this.  This is pseudocode, but you may be able to get what I mean here.


String myString = char(36) + myDouble;

String myString = char(128) + myDouble;

36 would be $
128 would be €

This function I put in is just something pulled from MS Office, but there probably is something similar in what you are programming with.

Are you able to just simply put "$" + myDouble in your code?
0
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37807472
You can use an ENUM:

public enum CurrencyType {
    Pound, Dollar, Lyra, Sheckel }
public class EnumTest {
    Day day;
    
    public CurrType(Currency Type Money) {
        this.Money = Money;
    }
    
    public void MoneyIsFun() {
        switch (Money) {
            case Pound:
                System.out.println("<insert ASCII Symbol here>");
                break;
                    
            case Dollar:
                System.out.println("<insert ASCII Symbol here>");
                break;
                         
            case Lyra: case Sheckel :
                System.out.println("<insert ASCII Symbol here>");
                break;
                        
            default:
                System.out.println("<insert ASCII Symbol here>");
                break;
        }
    }
    
    public static void main(String[] args) {
        EnumTest firstCash = new CurrType(Money.Dollar);
        firstCash.MoneyIsFun();
        EnumTest thirdCash = new CurrType(Money.Pound);
        thirdCash.MoneyIsFun();
        EnumTest fifthCash = new CurrType(Money.Sheckel);
        fifthCash.MoneyIsFun();
        EnumTest sixthCash = new CurrType(Money.Lyra);
        sixthCash.MoneyIsFun();
    }
}

Open in new window


This way you can assign more stuff to it, and do more things.
Hope it helps.
0
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 37807515
Here's a link to what I'm talking about: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 37808610
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37813967
:)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
custom annotations 9 38
diffSum example 4 36
JAVA API design with micro service cloud in mind 1 10
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now