Thoughtworks agile bootcamp problem solution in Core Java
Inventory Management Recently a new online store opened on the Internet that sells iPods & iPhones. They are faced with an interesting problem of managing their inventory distributed across 2 countries: Brazil and Argentina. You have been assigned to write a program to minimize the sale price for online customers based on its inventory in these 2 countries. The price are different based on the country where the inventory is stored. The inventory in the two countries is limited. There are 100 iPods in Brazil which have a sale price of $65 whereas there are 100 in Argentina which have a sale price of $100. There are 100 iPhone in Brazil which have a sale price of $100 whereas there are 50 in Argentina which have a sale price of $150. For simplicity we will use US dollars as our transaction currency. The order should be fulfilled fully or not at all. If the inventory from one country in used up item have to be fetched from the other country. There is a transport cost involved when the item needs to be shipped from one country to another in case the purchase country is different than the inventory country. Shipping cost is $400 for every 10 units of item type (no mixing of item types). Note that transport cost is always in multiples of 10 units. If customer passport belongs to local country then the customer will get 20% discount on the transport cost. For example a customer placing order from Argentina and has a passport of Brazil, while shipping order from Brazil the transport cost will be charged ($400 - 20% = $320) for every 10 units. To identify passport from brazil, passport number starts with B, followed by 3 digits, followed 2 chars, followed by 7 alphanumeric characters. And for Argentina, passport number starts with A, followed by 2 chars, followed by 9 alphanumeric characters. To minimize the total sales price it can be partly fulfilled from one country and remaining from other. Assume that before each purchase order the inventory is replenished to its normal level. Thus the orders are independent of each other.
Use following input/output to understand the problem better. If there is something which is not clear, do not hesitate to post your questions on AgileDevBootcamp forum. Also if you find any discrepancies in the problem or sample input/output please let us know.
INPUT FORMAT: (no space between separators) <purchase_country>:<optional_passport_number>:<item_type>:<number_of_ units_to_be_ordered>:<item_type>:<number_of_units_to_be_ordered>
OUTPUT FORMAT: <total_sale_price>:<ipod_brazil_inventory>:<ipod_argentina_inventory> :<iphone_brazil_inventory>:<iphone_argentina_inventory>
INPUT 1: BRAZIL:B123AB1234567:IPHONE:20:IPOD:10 OUTPUT 1: 2650:90:100:80:50
INPUT 2: ARGENTINA:B123AB1234567:IPHONE:22:IPOD:10 OUTPUT 2: 3910:90:100:80:48
INPUT 3: BRAZIL:AAB123456789:IPHONE:125:IPOD:70 OUTPUT 3: 19260:30:100:0:25
INPUT 4: ARGENTINA:AAB123456789:IPOD:50:IPHONE:25 OUTPUT 4: 8550:100:50:80:45
INPUT 5: BRAZIL:IPHONE:50:IPOD:150 OUTPUT 5: 18500:0:50:50:50
INPUT 6: BRAZIL:IPHONE:250:IPOD:150 OUTPUT 6: OUT_OF_STOCK:100:100:100:50
Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions.
When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.
Write an application that prints out the receipt details for these shopping baskets...
Input 1:
1 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
Input 2:
1 imported box of chocolates at 10.00
1 imported bottle of perfume at 47.50
Input 3:
1 imported bottle of perfume at 27.99
1 bottle of perfume at 18.99
1 packet of headache pills at 9.75
1 box of imported chocolates at 11.25
Output 1:
1 book : 12.49
1 music CD: 16.49
1 chocolate bar: 0.85
Sales Taxes: 1.50
Total: 29.83
Output 2:
1 imported box of chocolates: 10.50
1 imported bottle of perfume: 54.65
Sales Taxes: 7.65
Total: 65.15
Output 3:
1 imported bottle of perfume: 32.19
1 bottle of perfume: 20.89
1 packet of headache pills: 9.75
1 imported box of chocolates: 11.85
Sales Taxes: 6.70
Total: 74.68