class InvestmentProfile(val rate: Double, val periods: Int) class InvestmentCalculator: // the value of an investment of $principle after specified years def value(principle: Double, years: Int)(using fc: InvestmentProfile) = var result = principle val rate2 = fc.rate / fc.periods for(i <- 0 until years * fc.periods) result += rate2 * result result object scenario extends InvestmentCalculator with App : // 100% annual rate compounded monthly val profile1 = InvestmentProfile(1, 12) // 100% annual rate compounded daily val profile2 = InvestmentProfile(1, 365) // the default profile given InvestmentProfile = profile1 // investing $1 for 1 year val payoff1 = value(1, 1) val payoff2 = value(1, 1)(using profile2) println("payoff1 = $" + payoff1) // $2.613035290224677 println("payoff1 = $" + payoff2) // $2.714567482021875