Statistics

Problem Statement for "CheckbookRegister"

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.

  5. 9876

    1234

    5678

    Returns: 2964

  6. 500

    400

    200

    Returns: -100

  7. 500

    200

    400

    Returns: -100

  8. 1000

    500

    501

    Returns: -1

  9. 500

    250

    50

    Returns: 200

  10. 500

    200

    50

    Returns: 250

  11. 100

    0

    5

    Returns: 95

  12. 1

    20

    80

    Returns: -99

  13. 2

    20

    80

    Returns: -98

  14. 500

    600

    700

    Returns: -800

  15. 1

    2

    3

    Returns: -4

  16. 1000

    700

    98

    Returns: 202

  17. 200

    200

    100

    Returns: -100

  18. 1000

    100

    100

    Returns: 800

  19. 10

    2

    2

    Returns: 6


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: