-
Refer CodeKata for the complete Problem Description
-
Summary of problem
- Individual letters of the alphabet (A, B, C, and so on) are used to identify goods/items in a store.
- Goods are priced individually.
- In addition, some items are multi-priced: buy n of them, and they'll cost you y cents. (Eg: item 'A' might cost 50 cents individually. But, buy three 'A's and they'll cost you $1.30).
- checkout accepts items in any order. So that if we scan a B, an A, and another B, we'll recognize the two B's and price them at 45 (for a total price so far of 95).
- Because the pricing changes frequently, we need to be able to pass in a set of pricing rules each time we start handling a checkout transaction.
- This week's prices are as follows:
Item Unit Price Special Price
-------------------------------------
A 50 3 for 130
B 30 2 for 45
C 20
D 15
kata-09
├───images
├───pom.xml
├───README.md
├───src
│ ├───main
│ │ └───java
│ │ └───com.codekata.kataNine
│ │ │ ├───CheckOut.java
│ │ │ └───KataApp.java <-- uses KataNineUtil to set up CheckOut
│ │ │
│ │ ├───com.codekata.model
│ │ │ └───PricingRule.java
│ │ │
│ │ └───com.codekata.util
│ │ └───KataNineUtil.java <-- define pricing rules here
│ │
│ └───test
│ └───java
│ └───com.codekata.kataNine
│ └───CheckOutTest.java
│
└───target
└───kataNine-0.0.1-SNAPSHOT.jar
- Download the jar file from here.
- Navigate to the directory where the jar file is downloaded in terminal.
- Start the application using the code
java -cp kataNine-0.0.1-SNAPSHOT.jar com.codekata.kataNine.KataApp
- Set of JUnit tests for CheckOut.java can be found here.
- The
@BeforeEach
method is used to initialize the CheckOut object. - items are added to the cart using the scanItem() method and the actual and expected totals are compared.
- Different pricing rules can be defined by instantiating the PricingRule.java class
- KataNineUtil.java is used to define unit pricing and special pricing rules.
- A Screenshot of the interface for the checkout is shown below
- Java 8
- Maven
- JUnit 5
- Eclipse IDE