Immutable Money Type
hardQuestion 578The 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
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.