TopcoderARCHIVE
Archive/Problems/CheckbookRegister
SRM · Problem 13578

CheckbookRegister

Problem statement, definition, constraints, and public examples.

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

  1. 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)
  2. 500
    210
    290
    Returns: 0
    You're all out of money.
  3. 800
    0
    0
    Returns: 800
    You haven't spent any of your money in this case.
  4. 500
    300
    450
    Returns: -250
    Oops... you overdrew your account.
← All problems