Problem Statement
Your store sells some goods and you want to know how many goods you should order for the next month. You are given two int[]s, purchased and sold, representing the number of units of goods you purchased and sold during the previous months (the ith elements of purchased and sold represent the ith month). You think that the demand next month will be equal to the average demand during the previous months (rounded up). Also, you want to have reserve percent of average demand as a backup (also rounded up). Return the number of units of goods you must order (don't forget that you may have some goods left unsold from the previous months).
Definition
- Class:
- StoreSupply
- Method:
- nextOrder
- Parameters:
- int[], int[], int
- Returns:
- int
- Method signature:
- int nextOrder(int[] purchased, int[] sold, int reserve)
- (be sure your method is public)
Notes
- The goods that you purchase one month are available to be sold that same month.
- When computing the number of goods to purchase, you must round up twice. First, you must round the average up to get the expected demand, then you must round up again to figure out how many reserves you need.
Constraints
- purchased and sold will contain the same number of elements.
- purchased and sold will each contain between 1 and 50 elements, inclusive.
- All elements in purchased and sold will be between 0 and 1000, inclusive.
- At the beginning of each month, the store will have enough goods to sell during that month.
- reserve will be between 0 and 200, inclusive.
Examples
{1, 1, 1, 1, 1}{1, 1, 1, 1, 1}100
Returns: 2
You sell 1 unit every month. You want to have 100% of the average demand as backup, so you need to order 2 units.{1, 1, 1, 1, 1}{1, 1, 1, 1, 1}101
Returns: 3
Similar example, but you want to have an extra 101% of goods. Since you should round up, you must order 3 goods.{1, 1, 1, 1, 1}{1, 1, 1, 1, 1}1
Returns: 2
Round up carefully.{655, 480, 965, 795, 298}{655, 480, 965, 586, 445}127
Returns: 1362
The average of the previous sales is 626.2. Rounding this up, we expect the demand to be 627. 127% of 627 is 796.29, which we round up to 797. Hence, we would like to have 627+797=1424 units for the next month. Since we have 62 units left over from the previous monthes, we need to order 1362.{972, 992, 655, 443, 639, 215, 630, 407, 577, 134, 231, 366, 456, 903, 475, 501, 76, 876, 112, 637, 109, 452, 135, 539, 712, 43, 714, 622, 929, 556}{972, 75, 28, 79, 184, 473, 623, 16, 392, 389, 673, 361, 476, 275, 825, 185, 378, 35, 171, 568, 937, 715, 28, 366, 871, 406, 195, 617, 207, 437}105
Returns: 0
You have enough goods in the store.