← Back to Encapsulation
Question 571
Guarding Against Negatives
Guarding Against Negatives
TheAccountclass has a private fieldbalance. Add aBalanceproperty whosegetreturns the field and whosesetstoresvalueonly when it is 0 or greater; a negativevaluemust be stored as 0. Do NOT write aMainmethod. ForBalance = -50the program prints the output shown in Expected Output. ForBalance = 100the program prints: 100
Expected Output:
0= newline. The output ends with a newline — 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.