Creating objects of the Currency class requires a name (string), a currency symbol (string) and the number of decimal places (integer) usually associated with the currency (in that order).

LANGUAGE:  C++

CHALLENGE:

Creating objects of the Currency class requires a name (string), a currency symbol (string) and the number of decimal places (integer) usually associated with the currency (in that order).

Define an object named curr, of type Currency corresponding to “US Dollar” with the symbol “$” and 2 decimal places.

SOLUTION:


public class Currency {
    String name;
    String symbol;
    int decimal;
  
    public static void main(String[] args) {
        Currency curr = new Currency();
        curr.name = "US Dollar";
        curr.symbol = "$";
        curr.decimal = 2;
  
        System.out.println("currency name : "+curr.name);
        System.out.println("Currency symbol : "+curr.symbol);
        System.out.println("Currency decimal places : "+curr.decimal);
    }
}