Posted on by Kalkicode
Code Mathematics

Program to calculate simple interest in kotlin

Kotlin Program to calculate simple interest. Here more solutions.

//  Kotlin program for
//  Calculate simple interest
class Interest {
    companion object {
        // Method which is take three parameters
        // And calculates that simple interest
        // Here time is form in year
        // rate is form of annual interest rate
        fun simpleInterest(principle : Number, 
                           time : Number, 
                           rate : Number) : Unit
        {
            // Display parameters values
            println("Principal : " + principle);
            println("Time : " + time);
            println("Rate : " + rate);
            // Calculate interest
            val amount : Double = (principle.toDouble() * 
                                   time.toDouble() * 
                                   rate.toDouble()) / 100;
            // Display amount
            println("Simple Interest : " + amount + "\n");
        }
    }
}
fun main(args : Array<String>) : Unit
{
  // Test Cases
  Interest.simpleInterest(1500, 3, 7.3);
  Interest.simpleInterest(170.4, 7, 3.4);
}

Output

Principal : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principal : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.55519999999999

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment