Problem Statement
You need to update the balance in your checkbook. You know your starting balance, the total amount spent using your debit card, and the total value of checks that have been written. Return your ending balance.
Definition
- Class:
- CheckbookRegister
- Method:
- updateBalance
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int updateBalance(int startingBalance, int debits, int checks)
- (be sure your method is public)
Notes
- Just like in real life, it's possible for you to end up negative.
Constraints
- startingBalance will be between 1 and 10000, inclusive.
- debits will be between 0 and 10000, inclusive.
- checks will be between 0 and 10000, inclusive.
Examples
1000
100
200
Returns: 700
You had 1000, withdrew 100 at an ATM, and wrote a check for 200. That leaves you with 700. (1000 - 100 - 200 = 700)
500
210
290
Returns: 0
You're all out of money.
800
0
0
Returns: 800
You haven't spent any of your money in this case.
500
300
450
Returns: -250
Oops... you overdrew your account.
9876
1234
5678
Returns: 2964
500
400
200
Returns: -100
500
200
400
Returns: -100
1000
500
501
Returns: -1
500
250
50
Returns: 200
500
200
50
Returns: 250
100
0
5
Returns: 95
1
20
80
Returns: -99
2
20
80
Returns: -98
500
600
700
Returns: -800
1
2
3
Returns: -4
1000
700
98
Returns: 202
200
200
100
Returns: -100
1000
100
100
Returns: 800
10
2
2
Returns: 6