Discount Code

BJ is out of town visiting family this weekend. Before flying out he went to the bookstore to purchase something to read on the flight and then drive. A lot of times bookstores will have sales or discounts that change their normal course of business.

The Challenge

For this challenge we are going to be applying various discounts based on sales criteria. We’ll be working with some math, string manipulation, and conditional logic. The goal is to interpret business requirements from the bookstore’s sales department as we build a way for them to enter the items sold and have the app use logic to know which discounts to calculate based on the input.

At each level you’ll need to take in certain information about the purchase: Book Title, Author Name, Publish Date, and Price. In addition you’ll also need to take in a coupon or discount code.

Creating a Test Case

No matter the level you choose to work with write a test case before you start your code. Then write just enough code to pass the test. Once you have passing code refactor to pass other test cases.

Level 1

For level 1 we’ll be applying a coupon or discount code to the entire purchase. The sales person will need to enter several books with full information and then be prompted to enter a coupon or discount code. Once all the details have been entered add up the cost of the books and apply the discount. Return the final cost of the books.

Hint: DiscountedPrice = Price - (Price (DiscountPercent / 100)). So a 5% discount on a $10 purchase would be: $9.50 = $10 - ($10 (5 / 100)).

A Step Further

The sales team really likes the ability to see the total with discount after they enter all the items, however customers would like to know how much they are spending while the items are being entered. They want you to provide a running total as new items are added to the purchase show the total. Then add the ability to enter the discount code at any time in the entry process and apply it to the running total.

Level 2

The sales team has mentioned that they occasionally have time limited sales. In this case the discount codes will only be valid for a certain time-frame or in certain circumstances. Check that the discount code is valid before applying it to the total.

Hint: You don’t have to know the details of the sale to know whether a code is valid. You may just have a list of valid codes to compare with the one entered.

A Step Further

The sales team has informed you that they have different sales running at the same time. Add the ability to have different percentages based on the discount code entered.

Code Discount

Level 3

The sales team is running a special on multiple purchases from the same author. Whenever a customer purchases more than one book from an author they will be given a discount only on the books after the first one by the same author. This is going to happening at different times at different location so the individual stores will need the ability to turn this feature on and off. Also make sure that the sales team doesn’t lose functionality by applying these new discounts. You’ll need to still show a running total with applicable discounts.

Hint: For this challenge we will assume that all author names are unique with no authors sharing the same name.

A Step Further

Based on the popularity of the same author discount the sales team has added a same series discount. This is an increasing discount so that if books from the same series by the same author are purchased they receive an increasing discount. The second book in the series will get 5% off, the third book 10%, the fourth 15% and so forth. The discount will max out at 35%.

Hint: You can put series information in the title of the books or add a field to the input that contains the series information.