Design a BankAccount class that tracks a single account balance and enforces its own deposit and withdrawal rules.
Implement the BankAccount class:
BankAccount(String accountNumber, String ownerName) creates an account with the given number and owner. The balance starts at 0.boolean deposit(double amount) adds amount to the balance and returns true. If amount is not greater than zero, it changes nothing and returns false.boolean withdraw(double amount) subtracts amount from the balance and returns true. If amount is not greater than zero, or the balance is smaller than amount, it changes nothing and returns false.double getBalance() returns the current balance.String getSummary() returns the account as "<ownerName> (<accountNumber>) | Balance: $<balance>", with the balance formatted to exactly two decimal places and no thousand separators. An account owned by John Doe with number ACC-123 and a balance of 500 gives "John Doe (ACC-123) | Balance: $500.00".The balance must not be reachable or assignable from outside the class. Every rule above has to be enforced by the object itself.
Input:
Output:
Explanation:
BankAccount account = new BankAccount("ACC-123", "John Doe"); // balance is 0account.deposit(1000); // returns true, balance is 1000account.getBalance(); // returns 1000.0account.withdraw(500); // returns true, balance is 500account.getBalance(); // returns 500.0account.withdraw(1000); // returns false, 1000 is more than the balance, nothing changesaccount.getSummary(); // returns "John Doe (ACC-123) | Balance: $500.00"Input:
Output:
Explanation: A negative deposit, a zero deposit, and a withdrawal from an empty account are all rejected, so the balance stays at 0.
1 <= accountNumber.length <= 201 <= ownerName.length <= 50-10^6 <= amount <= 10^6100 calls will be made across all methods.Full marks when accountNumber, ownerName and balance are all private (or the language's closest equivalent) and there is no setter that lets a caller assign the balance directly. Lose points for public or package-visible mutable state, or for a setBalance method that bypasses the deposit and withdraw rules.
Full marks when the amount validation lives inside deposit and withdraw so the object protects its own balance. Lose points if the checks are missing, duplicated across methods in a way that could drift, or clearly written to satisfy specific test values rather than the stated rule.
Full marks for a single cohesive class with descriptive names and no dead code. Lose points for unused fields, stray debug printing, or logic unrelated to a bank account.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new BankAccount("ACC-123", "John Doe") | null |
| deposit(1000) | true |
| getBalance() | 1000 |
| withdraw(500) | true |
| getBalance() | 500 |
| withdraw(1000) | false |
| getSummary() | "John Doe (ACC-123) | Balance: $500.00" |
A deposit of 1000 succeeds. Withdrawing 500 succeeds and leaves 500. Withdrawing 1000 from a balance of 500 fails and changes nothing.
Run checks these cases. Submit also runs a larger hidden set.

