/**
 * Calculate the interest amount based on the principal and rate.
 * If the rate is less than 0, the function will raise a IllegalArgumentException.
 * If the rate is between 0 and 1, returns the interest amount as a Float.
 * If the rate is greater than or equal to 1, returns the interest amount as an Int.
 *
 * @param principal The principal amount.
 * @param rate The interest rate.
 * @return The interest amount as Float or Int.
 */
fun calculateInterest(principal: Float, rate: Float): Number {

    // Check if the rate is less than 0
    if (rate < 0) {
        throw IllegalArgumentException("Rate cannot be less than 0.")
    }

    // Check if the rate is between 0 and 1
    else if (rate >= 0 && rate < 1) {
        val interest = principal * rate
        return interest
    }

    // Check if the rate is greater than or equal to 1
    else if (rate >= 1) {
        val interest = principal / rate
        return interest.toInt()
    }

    throw IllegalArgumentException("Invalid rate value.")
}
/**
 * Calculate the interest amount based on the principal and rate.
 * If the rate is less than 0, the function will raise a IllegalArgumentException.
 * If the rate is between 0 and 1, returns the interest amount as a Float.
 * If the rate is greater than or equal to 1, returns the interest amount as an Int.
 *
 * @param principal The principal amount.
 * @param rate The interest rate.
 * @return The interest amount as Float or Int.
 */
fun calculateInterest(principal: Float, rate: Float): Number {
/**
 * Calculate the interest amount based on the principal and rate.
 * If the rate is less than 0, the function will raise a IllegalArgumentException.
 * If the rate is between 0 and 1, returns the interest amount as a Float.
 * If the rate is greater than or equal to 1, returns the interest amount as an Int.
 *
 * @param principal The principal amount.
 * @param rate The interest rate.
 * @return The interest amount as Float or Int.
 */
fun calculateInterest(principal: Float, rate: Float): Number {

    // Check if the rate is less than 0
    if (rate < 0) {
        throw IllegalArgumentException("Rate cannot be less than 0.")
    }

    // Check if the rate is between 0 and 1
    else if (rate >= 0 && rate < 1) {
        val interest = principal * rate
        return interest
    }

    // Check if the rate is greater than or equal to 1
    else if (rate >= 1) {
        val interest = principal / rate
        return interest.toInt()
    }

    throw IllegalArgumentException("Invalid rate value.")
}