Skip to content

Instantly share code, notes, and snippets.

View DhavalDalal's full-sized avatar
🇮🇳
https://twitter.com/softwareartisan

Dhaval Dalal DhavalDalal

🇮🇳
https://twitter.com/softwareartisan
View GitHub Profile
@DhavalDalal
DhavalDalal / Attention.md
Last active April 7, 2024 05:45
Loyalty Points - C#

Loyalty Points (C#)

  • Create a C# Library Project - you can name it LoyaltyPoints.
  • Copy PointsCalculatorTest.cs under project PrivilegeServiceSpecs. Add reference to NUnit in this project.
  • Copy Tier.cs, PrivilegeService.cs, PointsCalculator.cs, CustomerRepository.cs and Customer.cs under project PrivilegeService.
  • Run the tests to get a green bar.

An airline has following rules for calculating bonus amount for loyalty points for a customer based on which tier they are in:

  • If a customer is in Platinum tier, add 50% more points above regular points.
@DhavalDalal
DhavalDalal / Attention.md
Last active February 12, 2024 12:09
Loyalty Points - Java

Loyalty Points (Java)

  • You can use Gradle to create a Java Project - you can name it LoyaltyPoints.
  • Copy PointsCalculatorTest.java under package loyaltyPoints within src/test/java
  • Copy Tier.java, PrivilegeService.java, PointsCalculator.java and Customer.java under package loyaltyPoints within src/main/java
  • Add JUnit4 or JUnit5 Jar or latest JUnit as a test dependency.
  • Run the tests to get a green bar.

An airline has following rules for calculating bonus amount for loyalty points for a customer based on which tier they are in:

@DhavalDalal
DhavalDalal / Attention.md
Last active March 3, 2023 06:51
Smelly Mars Rover in Java

Smelly Mars Rover (Java)

A squad of robotic rovers is to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rover so that its on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control the rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

@DhavalDalal
DhavalDalal / Attention.md
Last active September 15, 2022 08:58
Identify the Code-Smell?

Identify the Code Smells

  • Can you identify the code-smell?
  • How will you Refactor it?
@DhavalDalal
DhavalDalal / Attention.md
Last active March 1, 2022 21:08
Portfolio Tracker in C#

Portfolio Tracker (C#)

  • Track individual stocks worth and
  • Net worth of the portfolio.

Pre-Requisites

  • It requires JSON.NET. You can download it from http://www.newtonsoft.com/json
  • If you are within a proxy, you can do it programmatically like this:
    System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port); 
    
@DhavalDalal
DhavalDalal / Attention.md
Last active February 18, 2022 10:09
Smelly JDBC Code

Smelly JDBC Code (Java)

@DhavalDalal
DhavalDalal / Attention.md
Last active February 17, 2022 10:24
Thread-Safe Counter (Java)

Thread-Safe Counter (Java)

@DhavalDalal
DhavalDalal / 1_README.md
Last active July 27, 2021 08:00
Bank Maker-Checker Refactoring (Java)

Bank Maker-Checker Refactoring (Java)

@DhavalDalal
DhavalDalal / Attention.md
Last active September 22, 2020 02:42
Echo TCP-Server (Java)

Echo TCP Server (Java)

@DhavalDalal
DhavalDalal / Attention.md
Created April 17, 2020 10:54
Refactoring - ocp
  • How can I use circle, square, triangle and any shape that comes in future to draw?
  • How can I draw pictures that are composed from triangles, squares, or circles or any future shape?
  • I want to make sure that always circles are drawn first, squares are second and triangles are third?