Problem Statement
Recording artist royalties for commercial music albums are sometimes paid as a percentage of the album's suggested retail price. First, a packaging percentage is subtracted from the suggested retail price of the album (since that portion is paid for by the record company). Then, a percentage of the remaining price is set aside for artist royalties. This amount is multiplied by the number of units sold. However, the record company usually gives the artist cash advances during the recording process (for studio time, equipment, etc...). These advances must be recouped by the record company before any royalties are paid out. Given the suggested retail price of an album (formatted as "$XX.XX", where each X is a single digit), the number of units sold, the packaging percentage, the royalty percentage, and the advances given by the record company (in dollars), determine how much the recording artist will earn. Return this value as a double representing the amount earned by the artist in dollars. If the royalty total after subtracting advances is negative, return 0. See the examples for a more detailed explanation.
Definition
- Class:
- ArtistRoyalties
- Method:
- royalties
- Parameters:
- String, int, int, int, int
- Returns:
- double
- Method signature:
- double royalties(String retailPrice, int unitsSold, int packagingPercentage, int royaltyPercentage, int advances)
- (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 10000000, inclusive.
- packagingPercentage will be between 1 and 50, inclusive.
- royaltyPercentage will be between 1 and 50, inclusive.
- advances will be between 0 and 500000, inclusive.
Examples
"$18.00"
500000
25
15
150000
Returns: 862500.0
Before calculating the royalties, the packaging percentage is subtracted from the suggested retail price. 25% off of $18 is $13.50. For each unit sold, the artist will earn 15% of $13.50 = $2.025. $2.025 * 500,000 units = $1,012,500. The record company must recoup the $150,000 in advances, so that amount is subtracted from the total given to the artist."$19.99"
7900
34
10
5000
Returns: 5422.786000000002
The artist is owed approximately $5422.79."$38.88"
70000
40
9
200000
Returns: 0.0
Even after selling 70,000 copies, the artist will remain in debt to the record company because of the $200,000 advance."$09.49"
9000000
18
50
500000
Returns: 34518100