function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak Kumar Singh 15Deepak Kumar Singh 15 

write a program to calculate Simple Interest in Apex?

Best Answer chosen by Deepak Kumar Singh 15
mukesh guptamukesh gupta
Hi Deepak,

EXAMPLE: Input :
Principle = 10000
Rate = 5
Term = 5
Output :2500

We need to find simple interest on Rs. 10,000 at the rate of 5% for 5 units of time. 

Please follow below code:
 
public class InterestCalculator {
    public static void getIntrest(Decimal amount,Decimal Yrs,Decimal rate){
	Decimal SimpleIntrest = (amount*yrs*rate)/100
	
        System.debug('Get Interest>>> '+ SimpleIntrest); 
    }
}


for Testing you can check  In  anonymous window and execute below code

InterestCalculator.getIntrest(10000,5,5);


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 

All Answers

CharuDuttCharuDutt
Hii Deepak Kumar
Try Below Class
public class SimpleInterest {
    public static void calculateintrest(Integer principalAMT,Integer NumberOfYears,Decimal rate){
        System.debug('SimpleInterest>>> '+ ((principalAMT*NumberOfYears*rate)/100)); 
    }
}

//Execute In Anonymous Window
SimpleInterest.calculateintrest(1000,5,5.7);

#############################################
Integer principalAMT=  1000;
Integer NumberOfYears= 5;
Decimal rate = 5.7;
System.debug('SimpleInterest>>> '+ ((principalAMT*NumberOfYears*rate)/100)); 
Please Mark It As Best Answer If It Helps
Thank You!
mukesh guptamukesh gupta
Hi Deepak,

EXAMPLE: Input :
Principle = 10000
Rate = 5
Term = 5
Output :2500

We need to find simple interest on Rs. 10,000 at the rate of 5% for 5 units of time. 

Please follow below code:
 
public class InterestCalculator {
    public static void getIntrest(Decimal amount,Decimal Yrs,Decimal rate){
	Decimal SimpleIntrest = (amount*yrs*rate)/100
	
        System.debug('Get Interest>>> '+ SimpleIntrest); 
    }
}


for Testing you can check  In  anonymous window and execute below code

InterestCalculator.getIntrest(10000,5,5);


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
This was selected as the best answer