Git Product home page Git Product logo

santa-is-coming's Introduction

Java Christmas Project

Created a Java-based simulation of Santa Claus delivering gifts to children on Christmas Eve, utilizing object-oriented programming concepts such as design patterns, inheritance, polymorphism, and encapsulation. The project demonstrates practical application of OOP principles in a fun and engaging context.

Implementation

I have attempted to modularize the code as best as possible using the Command Pattern, Factory Pattern, Strategy Pattern, Singleton, and abstract class-based implementations. The comments placed in the code also explain certain functionalities quite well.

For the Command Pattern, I created a separate package that contains multiple packages that contain different commands.

For the classes that calculate the score for each child, I created an abstract class called Score, which is extended by the categories of children (Baby, Kid, Teen, Adult). Additionally, to calculate the score, we need to determine which class the child belongs to, so I used the ScoreFactory for this functionality. In the main method, I called the CalculateScore function in each round for each child. This returns the averageScore. For calculating the score for each city, I wrote a separate function that returns a descendingly ordered hashmap based on the score that I use in the NiceCityGiftStrategy to first distribute gifts to children based on the city and then based on the ID.

For the budget, I built two functions:

  • CalculateScoresSum -> Sums up all the averageScores of the children and sets the niceScore for each child by calling the CalculateScore function on the entire list of children.
  • CalculateChildBudget -> Calculates Santa's budget for each child (also called in each round, for each child). The CalculateScoreSum calls CalculateScore within it and modifies the "niceScore" parameter of each child at the beginning of each round.

I implemented elves using a factory. Elf modifications (except for yellow) are applied after calculating the budget for each child. To apply the modifications of the Yellow elf, after gift distribution, I check if the child received any gifts. If not, I apply the modifications of the elf.

Distribution takes place in SendChildListGifts, which is called by each gift distribution strategy in the order of the list given as a parameter, the order of which I modify based on the strategy.
Example: ID strategy -> I sort the list of children based on ID, then call the distribution function on the sorted list.
Each gift distribution strategy returns a JSONArray that contains the children who received gifts in that round.

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.