Problem

Gym Fees Calculator

Learn this problem
TCTCSOA

Problem statement

A gym offers membership plans with the following prices:

  • 3 months: 5000
  • 6 months: 9000
  • 9 months: 12000
  • 12 months: 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.

Function

calculateGymFees(months: int) → String

Examples

Example 1

months = 18return = "24000"

Use one 12-month plan and one 6-month plan, for a total cost of 15000 + 9000 = 24000.

Example 2

months = 15return = "20000"

Use one 12-month plan and one 3-month plan.

Example 3

months = 10return = "Error"

10 is not divisible by 3, so the requested length cannot be represented by the available plans.

Constraints

  • months >= 1

More TCS problems

drafts saved locally
public String calculateGymFees(int months) {
  // write your code here
}
months18
expected"24000"
checking account