Skip to content

Project simulates Santa delivering gifts to children. Emphasis on use of Design Patterns, Inheritance, Polymorphism, Encapsulation.

Notifications You must be signed in to change notification settings

eduardspirache/Santa-is-Coming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Project simulates Santa delivering gifts to children. Emphasis on use of Design Patterns, Inheritance, Polymorphism, Encapsulation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published