CJCoding With Joseph
15free / daySign inCreate account

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 the output shown in Expected Output.

Expected Output:

15 USD

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Encapsulation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.