monthly income, monthly expense then based on my savings i want to check how much loan i…
- User
monthly income, monthly expense then based on my savings i want to check how much loan i will get and that loan amount repayment at particular rate of interest and how much my monthly emi will be, please give me kotlin code
- Assistant
Sure! Here's a Kotlin code snippet that calculates the loan amount, monthly EMI, and repayment based on the monthly income, expenses, and savings:
import kotlin.math.roundToInt fun main() { val monthlyIncome = 50000.0 // Example monthly income val monthlyExpense = 20000.0 // Example monthly expense val savings = 100000.0 // Example savings val loanAmount = calculateLoanAmount(monthlyIncome, monthlyExpense, savings) val interestRate = 5.0 // Example annual interest rate in percentage val emi = calculateEmi(loanAmount, interestRate) val repaymentAmount = calculateRepaymentAmount(emi, loanAmount) println("Loan amount: $loanAmount") println("Monthly EMI: $emi") println("Repayment amount: $repaymentAmount") } fun calculateLoanAmount(monthlyIncome: Double, monthlyExpense: Double, savings: Double): Double { val availableFunds = monthlyIncome - monthlyExpense val loanAmount = savings + (availableFunds * 12) return loanAmount } fun calculateEmi(loanAmount: Double, interestRate: Double): Double { val monthlyInterestRate = interestRate / 12 / 100 val emi = (loanAmount * monthlyInterestRate * (1 + monthlyInterestRate).pow(12)) / ((1 + monthlyInterestRate).pow(12) - 1) return emi } fun calculateRepaymentAmount(emi: Double, loanAmount: Double): Double { val repaymentAmount = emi * 12 return repaymentAmount }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.