CJCoding With Joseph

Immutable Money Type

The Money class stores two readonly fields, amount (int) and currency (string), set in the constructor. Add a method Add(int extra) that returns a NEW Money with amount + extra and the same currency (it must not modify the current object), and a method Display() that returns the amount and currency separated by a single space. Do NOT write a Main method.

For new Money(10, "USD").Add(5).Display() the program prints:
15 USD

Expected Output:

15 USD
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.