DEV Community

Cover image for Code Kata #1: Bank Account
Thodoris Kouleris
Thodoris Kouleris

Posted on

Code Kata #1: Bank Account

The Problem

Write a class named BankAccount that implements the following public interface:

public interface BankAccount
{
    void deposit(int amount)
    void withdraw(int amount)
    void printStatement()
}
Enter fullscreen mode Exit fullscreen mode

(Note you can do this exercise in any programming language, translate the above code as appropriate)

Example statement
When you call the ‘printStatement’ method, something like the following is printed on standard output:

Date       || Amount || Balance
2012-01-14 || -500   || 2500
2012-01-13 || 2000   || 3000
2012-01-10 || 1000   || 1000
Enter fullscreen mode Exit fullscreen mode

This example statement shows one withdrawal on 14th January 2012, and two deposits on 13th and 10th January respectively.

Notes

  • You cannot change the public interface of the BankAccount
  • We’re using ints to represent money, which in general may not be the best idea. In a real system, we would always use a datatype with guaranteed arbitrary precision, but doing so here would distract from the main purpose of the exercise.
  • Don’t worry about matching the exact formatting of the bank statement, the important thing is to print a table that has column headings and which orders transactions by date.

the solution

Top comments (0)