Problem
Gym Fees Calculator
A gym offers membership plans with the following prices:
3months:50006months:90009months:1200012months:15000
You are given a requested membership length months. Calculate the total cost using the greedy priority order 12, then 9, then 6, then 3. Use as many plans as possible at each priority before moving to the next smaller plan.
If months is not divisible by 3, return "Error". Otherwise, return the total cost as a string.
Examples
01 · Example 1
months = 18 return = "24000"
Use one 12-month plan and one 6-month plan, for a total cost of 15000 + 9000 = 24000.
02 · Example 2
months = 15 return = "20000"
Use one 12-month plan and one 3-month plan.
03 · Example 3
months = 10 return = "Error"
10 is not divisible by 3, so the requested length cannot be represented by the available plans.
Constraints
months >= 1
public String calculateGymFees(int months) {
// write your code here
}months18
expected"24000"
sign in to submit