The application uses a Gradle-based build system. In the instructions
below, ./gradlew
is invoked from the root of the source tree and serves as
a cross-platform, self-contained bootstrap mechanism for the build.
To compile from the source code, run all the test cases and build jars:
./gradlew build
To run the application, import the project into an IDE and run the com.thoughtworks.cashiermachine.Main
class
Some samle products and promotions data is contained the following files
- src/main/resources/products.json
- src/main/resources/promotions.json
You can add more products and more promotion rules
There are 3 kinds of predefined promotion rules
-
Percentage promotion - add percentage discount to order item
-
BuyXGetYFree promotion - on every purchase of x items, customer will get y free
-
Composite promotion
Sometimes one product may be eligible for multiple promotions, but only the high priority promotion will take place.
In promotion settings we can combine promotions of different priorities into one promotion that contains a high priority promotion
as well as a low priority promotion. When this compisite promotion gets applied, it will determine which promotion will be applied to
the product. See src/main/resources/promotions.json
for example.