Music Cart

Here in Nashville we have a lot of musicians trying to make it big and some bigger ones continuing or changing their careers. Many of them do so using social media and even have their own websites while they are trying to get picked up by a record label. As the experts in computers we are here to help them out.

The Challenge

For this challenge we are going to be working on a variant of the shopping cart code kata. In it we will apply business logic to determine discounts and pricing for the items in our shopping cart.

In this case we are working with Lindsey, a local musician who needs a shopping cart built for her website. Lindsey currently has 3 self published album she is selling for $10 each.

If a fan purchases two different albums they will receive a 10% discount on the second album and if they purchase all three albums they get a 15% discount on the third but only if they purchase each of the three albums not three of the same album.

Creating a Test Case

A Unit Test looks at and tests a specific unit of code to see if it is returning what is expected. 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

Start by creating a simple view allowing users to select the album or albums they want to purchase. Then write a function that calculates the total cost for the purchase. Assuming that all sales are made here in Nashville now apply a 9.25% sales tax to the purchase. Finally display for the user the total amount of the purchase, the sales tax, and the amount after tax.

A Step Further

Remember if a fan purchases a second album different from the first there is a 10% discount on that album and if they purchase all three albums there is a 15% discount on the third album. However if they purchase two or three copies of album 1 the discount does not apply.

Level 2

Lindsey has produced another album and is going on tour to promote her new album. As a thank you to her fans and to encourage more purchases she wants to give anyone that purchases the new album at full price 5% discount on any other albums they purchase on top of any other discounts that might apply.

A Step Further

As a special thanks to her fans who attend the concerts in her tour Lindsey is including with the ticket a discount code (LINDSEYROCKS!) for 4% off her fourth album. Add an input field for users to input the discount code if they have it. Then apply this discount only to album 4 along with the previous discounts.

Level 3

Lindsey also wants to include t-shirts at $20 each, sheet music at $15 each, and individual songs at $2 each. Add these to the shopping cart. Each album contains 8 songs, if a person buys all 8 songs on an album they should be charged the album price of $10 instead of the cost of all 8 individual songs. If a person purchases all of the individual songs of an album the same album rules apply so far as discounts are concerned. Including the 5% off with purchase of the fourth album at full price in Level 2.

A Step Further

Going all out for her superfans Lindsey is giving a discount to those that purchase only the songs from the set list of her tour concerts. If the fan purchases all of these songs individually each song is $1 instead of $2.

Lindsey’s Set List

Album Song
album 3 song 4
album 4 song 2
album 4 song 4
album 1 song 8
album 2 song 3
album 4 song 5
album 1 song 1
album 3 song 8
album 4 song 1
album 2 song 6