Giter Club home page Giter Club logo

bowlingscoremanager's Introduction

To resolve the proposed problem  I have decided to do it from a OOP perspective. For this porpouse, I have used Java and JUnit which led me to a TDD (Test-Driven Development) resolution.  

Phase 1: Define steps to achive the resolution:

    1 step:
         - Register 2 throws per frame.
         - Save the score of both throws in the current frame.
         - Run the game for a total of 10 Frames.
            + Check if the currentFrame is equal to total frames value.
         - Update the score list with each new frame.

    2 step:
        - Introduce the strike concept.
            + Check if first throw was 10.
            + Jump to the next frame.

    3 step:
        - Introduce the spare concept.
            + Check if both throws are equal to 10.

    4 step:
        - In the last frame, introduce an extra throw.
            + Check if it is the last frame and allow an extra throw. 


Phase 2: Define the tests for each step in phase 1;

Phase 3: Code based in test succesful.

Phase 4: Debuge to achieve the resolution, refactoring and improving the code. 


I have defined two classes + the main class which is the entry point.

    GameController which is responsible of:
        - Initialize variables.
        - Register a new throw.
        - Register  a list of Frame Objects.
        - Register and update the score.

        Interface GameController{
                public void newThrow(int pins);
                private void updateFrames();
                private void updateScores();
                public int getScoreAtFrame(int frame);
                public boolean gameIsOver();
        }


    Frame which is responsible of:
        - Register throws.
        - Check if it is a Strike.
        - Check if it has a Spare.
        - Save the score from all throws in this frame.

        This class was designed with variables, getters and setters.

        Class Frame {
            private Integer throw1;
            private Integer throw2;
            private Integer extraThrow;
            private int score;
            private boolean isScorePending;
            private boolean isStrike;
            private boolean isSpare;
        }


In order to try the application, you can run the test defined with JUnit or run the jar file using as argument a throw list ( E.g: java -jar BowlingGame.jar 5 2 8 1 10 3 2 10 10 1 6 10 2 6 10 4 5 )   

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.