Problem Statement | |||||||||||||
Margin is defined as the percentage of the selling price of an item or group of items which is profit. For example, if an item costs $80 and is sold for $100, then there is $20 profit, or 20% margin.
You will be given a String[], items, which is all of the items sold in a single transaction. Each String in items will be formatted as follows: "nnn.nn nnn.nn" (quotes for clarity), where each n is a digit between '0' and '9' inclusive. Each String will be exactly 13 characters in length. The first number listed is the price the customer paid for the item. The second number is what the cost to the store of the item was. You will create a class MarginCalculator with a method percent which will calculate the percentage of margin on the transaction and return it as an int, rounded down to the greatest integer less than the actual value. For example, let's say you were given the following String[]: { "012.99 008.73", "099.99 050.00", "123.45 101.07" }The total cost is $159.80. The total price is $236.43. That means $76.63 was made on this sale. This would be a 32.41128% margin. Since we are rounding down, you would return 32. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | The cost for some items may be greater than the price they was sold for. However, the sum of the prices of all the items in the transaction will be greater than the sum of the costs of all items. | ||||||||||||
Constraints | |||||||||||||
- | items will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Every String in items will be exactly 13 characters in length. | ||||||||||||
- | Every String in items will be formatted as "nnn.nn nnn.nn" where each n is a digit between '0' and '9' inclusive, thus the range for each price will be between "000.00" and "999.99" inclusive (all quotes for clarity). | ||||||||||||
- | The total price of all items will be greater than the total cost of all items. | ||||||||||||
- | The total price of all items will be greater than 0. | ||||||||||||
- | The percent of margin, prior to rounding, will not be within 1e-5 of an integer. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|