Problem Statement
Songwriter royalties for commercial music albums are sometimes paid out according to a penny rate. The penny rate is the number of cents the record company pays for each song on each unit sold of an album. Songs with playing times of five minutes or less are paid the standard rate, while songs longer than five minutes are paid a special per-minute rate. The royalties are paid to the publisher who then gives a certain percentage to the songwriter. Assume that a single songwriter has written all the songs on a particular album. Given the lengths of all the songs on the album (in minutes), the number of units sold, the standard and per-minute penny rates, and the percentage given to the songwriter by the publisher, determine how much the songwriter will earn in royalties from album sales. Return the number of dollars earned as a double. See the examples for a more detailed explanation.
Definition
- Class:
- SongwriterRoyalties
- Method:
- royalties
- Parameters:
- int[], int, int, int, int
- Returns:
- double
- Method signature:
- double royalties(int[] lengths, int unitsSold, int songRate, int perMinuteRate, int royaltyPercentage)
- (be sure your method is public)
Notes
- The return value must have an absolute or relative error of 1e-9.
Constraints
- lengths will contain between 1 and 30 elements, inclusive.
- Each element of lengths will be between 1 and 20, inclusive.
- unitsSold will be between 0 and 10000000, inclusive.
- songRate will be between 1 and 20, inclusive.
- perMinuteRate will be between 1 and 10, inclusive.
- royaltyPercentage will be between 1 and 100, inclusive.
Examples
{5, 1, 4, 13, 3, 4, 5, 6, 6}900000
10
2
50
Returns: 495000.0
The album contains nine songs - six of them have playing times of 5 minutes or less, and the remaining three are longer than 5 minutes. The six songs which are 5 minutes or less in length are each charged the song rate of 10 cents. The three longest songs are each charged the special rate of 2 cents per minute. The total royalty amount paid to the publisher is ((6 * 10) + (13 * 2 + 6 * 2 + 6 * 2)) * 900,000 = 99,000.000 cents = $990,000. 50% of this is given to the songwriter.{1, 1, 2, 1, 1, 4}555
9
2
72
Returns: 215.784
All six songs on this album are charged the standard song rate of 9 cents per song. The songwriter receives approximately $215.78.{5, 6}18000
8
1
75
Returns: 1890.0
Even though the second song is longer, it receives less money because of the rate structure in this scenario.{1, 5, 5, 6, 7, 4, 3, 8, 4, 5, 1}10000000
7
2
1
Returns: 98000.0