Giter Site home page Giter Site logo

xtenzq / atm-java Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 322 KB

Cash Machine test task for a Back End Developer position

Home Page: https://xtenzq.github.io/kmslh-test

Java 100.00%
cashmachine test-task command-pattern oop-java interview-task atm

atm-java's Introduction

Cash Machine Back End Developer Position Test Task

build test Coverage

A friendly reminder: If this repo somehow helped you please star ๐ŸŒŸ it! Thank you! ๐Ÿ˜„

Task

Is to create simple Cash Machine emulator.

Requirements (9/9 completed):

  • create stand-alone console I/O Java program using any JDK;
  • follow OOP paradigm;
  • make program easily extendable;
  • provide logging to the output file;
  • divide program modules into packages;
  • generate JavaDocs;
  • write JUnit tests for public methods;
  • make Ant build.xml;
  • make functional test.

Input commands:

  1. Cash deposit
Format: + <currency> <denomination> <amount>
Validation: 
* <currency> 3 uppercase letters, any combination
* <value> any value in set ["1","5","10","50","100","500","1000","5000"]
* <number> positive integer
Reply: OK on success, ERROR on validation fail
  1. Cash withdraw
Format: - <currency> <amount>
Reply: line formatted as <denomination> <amount> followed by OK on success, ERROR if amount is unavailable
  1. Cash print
 Format: ?
 Reply: OK, ordered by currency -> value

Run, build and test

Build

ant build

Test

ant test

Run

ant run

Solution

Before coding, we should make a plan:

  1. How to handle commands;
  2. Deposit/Withdraw strategy;
  3. I/O common interface.

Commands handling

To handle the command problem I decided to go for behavioral design Command pattern which delegates command build to the command factory.

I recommend to check Jairo Alfaro's reply on StackOverflow since he gives a good example of the implementation in C#.

Deposit/Withdraw strategy

I decided to arrange data in a structure Map<String, TreeMap<Integer, Integer>> since we basically have this kind of structure:

Structure

Since we have to pop up bigger banknotes first, we store Map<Integer, Integer> in a reverse order. In Java, TreeMap<Integer, Integer> stores keys in a natural order, so in our case we should apply Collections.reverseOrder() on initialization.

The rest of the algorithm is a piece of cake. For the deposit we simply add cash to the denomination, for the withdrawal we subtract the amount of remove the denomination if the amount is exact. Also, handle the situation when amount is unavailable (denomination absence, etc.).

I/O common interface

I created an I/O interface (InputReader & OutputWriter) and implemented corresponding reader and writer to work with streams. These classes can work both with System.in/System.out and FileInputStream/FileOutputStream so we can easily switch between file and console I/O.

atm-java's People

Contributors

xtenzq avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

axelway

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.