FunctionRacerProblemsRace

Bank Account Without Overdrafts

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class BankAccount for an account whose balance may never drop below zero. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

BankAccount(50)
withdraw(80) returns false
deposit(30) returns 80
withdraw(80) returns true
withdraw(1) returns false
get_balance() returns 0
count_rejected() returns 2

Taking 80 from 50 is rejected. After the deposit the balance is exactly 80, so that withdrawal works and leaves 0. Taking 1 from 0 is the second rejection.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems