โ Back to Encapsulation
Question 488
Immutable Money Type
Immutable Money Type
TheMoneyclass stores tworeadonlyfields,amount(int) andcurrency(string), set in the constructor. Add a methodAdd(int extra)that returns a NEWMoneywithamount + extraand the same currency (it must not modify the current object), and a methodDisplay()that returns the amount and currency separated by a single space. Do NOT write aMainmethod. Fornew 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.