Problem Statement
Recording artist royalties for commercial music albums are sometimes paid as a percentage of the album's suggested retail price multiplied by the number of units sold. Cash advances paid by the record company are subtracted from the total royalties owed to the recording artist. If this figure is negative, then no money is paid to the recording artist. Songwriter royalties, on the other hand, are sometimes paid by a penny rate to the publisher - the number of cents per song for each unit sold. Given the suggested retail price of the album (formatted as "$XX.XX", where each X is a single digit), the number of units sold, the number of songs on the album, the recording artist royalty percentage, the advances paid (in dollars), and the songwriter penny rate, determine how much the record company will earn from album sales. Return the number of dollars earned as a double. The advances paid to the artist must be factored into the result - for example, if the record company pays the artist $200,000 in advances, but the album sells 0 units, the record company will earn -$200,000. See the examples for a more detailed explanation.
Definition
- Class:
- RecordCompanySales
- Method:
- sales
- Parameters:
- String, int, int, int, int, int
- Returns:
- double
- Method signature:
- double sales(String retailPrice, int unitsSold, int numSongs, int artistRoyaltyPercentage, int advances, int pennyRate)
- (be sure your method is public)
Notes
- The return value must have an absolute or relative error of 1e-9.
Constraints
- retailPrice will be formatted as "$XX.XX", where each X is a single digit ('0'-'9'). There will be exactly two digits on both sides of the decimal point.
- unitsSold will be between 0 and 1000000, inclusive.
- numSongs will be between 1 and 30, inclusive.
- artistRoyaltyPercentage will be between 1 and 50, inclusive.
- advances will be between 0 and 500000, inclusive.
- pennyRate will be between 1 and 20, inclusive.
Examples
"$18.00"
100000
10
15
50000
8
Returns: 1450000.0
100,000 units are sold at $18 each for a total of $1,800,000. The recording artist receives 15% of $18 for each album sold. 0.15 * 18 * 100,000 = $270,000. Advances are subtracted from this amount. $270,000 - $50,000 = $220,000. The songwriter receives 8 cents for each of the 10 songs on the 100,000 units sold. 8 * 10 * 100,000 = 8,000,000 cents = $80,000. The record company receives $1,800,000 - $220,000 (recording artist royalties) - $80,000 (songwriter royalties) - $50,000 (advances) = $1,450,000."$28.93"
7777
8
23
200000
4
Returns: 22499.97
The record company makes $22,499.97."$09.96"
10
19
50
10000
6
Returns: -9911.8
The record company does not make enough money to recoup its advances. No money is paid to the recording artist, but the songwriter is still paid a royalty."$00.99"
1000000
2
16
0
20
Returns: 431600.0