GithubHelp home page GithubHelp logo

bank-tech-test's Introduction

Account Statement Printer

This repository contains code for a simple Bank Account Statement Printer.

Usage:

Firstly, clone this repo. Run bundle install

You can create a new transaction by using the Transaction class:

deposit = Transaction.new('10/01/2019', 1000, 'deposit')
withdrawal = Transaction.new('12/01/2019', 500, 'withdrawal')

This transaction can then be added to an account by using the Account class:

account = Account.new
account.add_transaction(deposit)
account.add_transaction(withdrawal)

Once you have some transactions in your account, you can print the statement using the StatementPrinter class:

statement = Statement.new

print (statement.return_statement(account))

This Prints a formatted statement to the console:

Output

Approach:

I initially started with the Bank class, using Tests to drive development. This inevitably led to the formation of three distinct classes as it became apparent that certain methods could be grouped together.

These methods were then extracted into the following classes:

Transactions Class

This is a simple class that takes in arguments for the date, transaction amount and the type of transaction. It returns an object that represents a single transaction.

Account Class

This is a class that has two attrributes: ledger and balance. It also contains a method for adding a transaction to the ledger. Depending on the transaction type, the balance will be adjusted accordingly.

Statement Class

The final class has no attributes associated with it. It has three methods. One that returns a formatted string representing a single transaction, another to return the headers and a final method that takes in an account object as an argument and returns a formatted, readable statement with the headers included.

NB the code for the example above is contained within example_script.rb

bank-tech-test's People

Contributors

bibbycodes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.