In this exercise, you'll be writing code to help a freelancer communicate with a project manager. Your task is to provide a few utilities to quickly calculate daily and monthly rates, optionally with a given discount.
We first establish a few rules between the freelancer and the project manager:
Sometimes, the freelancer is offering to apply a discount on their daily rate (for example for their most loyal customers or not-for-profit customers).
Discounts are modeled as fractional numbers representing percentages, for example, 25.0 (25%).
Implement a function called daily_rate to calculate the daily rate given an hourly rate as a parameter.
The contract defines that a day has 8 billable hours.
daily_rate(60)
// => 480.0The returned daily rate should be of type double.
Implement a function apply_discount to calculate the price after a discount.
It should accept two parameters: the original price and the discount rate in percent.
apply_discount(150, 10)
// => 135.0The returned value should always be of type double, not rounded in any way.
Implement a monthly_rate function to calculate the discounted monthly rate.
It should have two parameters, an hourly rate and the discount in percent.
monthly_rate(77, 10.5)
// => 12130The returned monthly rate should be rounded up (take the ceiling) to the nearest integer.
Implement a function days_in_budget that takes a budget, an hourly rate, and a discount, and calculates how many complete days of work that covers.
days_in_budget(20'000, 80, 11.0)
// => 35The returned number of days should be rounded down (take the floor) to the next integer.
In this exercise, you'll be writing code to help a freelancer communicate with a project manager. Your task is to provide a few utilities to quickly calculate daily and monthly rates, optionally with a given discount.
We first establish a few rules between the freelancer and the project manager:
Sometimes, the freelancer is offering to apply a discount on their daily rate (for example for their most loyal customers or not-for-profit customers).
Discounts are modeled as fractional numbers representing percentages, for example, 25.0 (25%).
Implement a function called daily_rate to calculate the daily rate given an hourly rate as a parameter.
The contract defines that a day has 8 billable hours.
daily_rate(60)
// => 480.0The returned daily rate should be of type double.
Implement a function apply_discount to calculate the price after a discount.
It should accept two parameters: the original price and the discount rate in percent.
apply_discount(150, 10)
// => 135.0The returned value should always be of type double, not rounded in any way.
Implement a monthly_rate function to calculate the discounted monthly rate.
It should have two parameters, an hourly rate and the discount in percent.
monthly_rate(77, 10.5)
// => 12130The returned monthly rate should be rounded up (take the ceiling) to the nearest integer.
Implement a function days_in_budget that takes a budget, an hourly rate, and a discount, and calculates how many complete days of work that covers.
days_in_budget(20'000, 80, 11.0)
// => 35The returned number of days should be rounded down (take the floor) to the next integer.