Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

monthly income, monthly expense then based on my savings i want to check how much loan i…

  1. 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

  2. Assistant

    Here is a Kotlin code that calculates the loan amount, monthly EMI and loan repayment based on monthly income, monthly expenses and savings:

    import java.util.*
    
    fun main() {
        val scanner = Scanner(System.`in`)
    
        println("Enter your monthly income:")
        val income = scanner.nextDouble()
    
        println("Enter your monthly expenses:")
        val expenses = scanner.nextDouble()
    
        println("Enter your savings:")
        val savings = scanner.nextDouble()
    
        println("Enter the loan interest rate (%):")
        val interestRate = scanner.nextDouble()
    
        val availableAmount = income - expenses + savings
    
        println("Available amount for loan: $availableAmount")
    
        println("Enter the loan duration (in months):")
        val loanDuration = scanner.nextInt()
    
        val loanAmount = availableAmount
    
        val monthlyInterestRate = interestRate / 100 / 12
        val emi = calculateEMI(loanAmount, monthlyInterestRate, loanDuration)
    
        println("Loan amount: $loanAmount")
        println("Monthly EMI: $emi")
        println("Total repayment amount: ${emi * loanDuration}")
    }
    
    fun calculateEMI(loanAmount: Double, monthlyInterestRate: Double, loanDuration: Int): Double {
        val emiNumerator = loanAmount * monthlyInterestRate * Math.pow((1 + monthlyInterestRate), loanDuration.toDouble())
        val emiDenominator = Math.pow((1 + monthlyInterestRate), loanDuration.toDouble()) - 1
        return emiNumerator / emiDenominator
    }
    

    This code takes input from the user for monthly income, monthly expenses, savings, loan interest rate, and loan duration. It then calculates the available amount for loan based on the provided information. The loan amount is set to the available amount, and the monthly EMI is calculated using the calculateEMI() function. Finally, the loan amount, monthly EMI, and total repayment amount are displayed to the user.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.