Results 1 to 8 of 8

Thread: How to calculate simple interest in java ?

  1. #1
    Join Date
    Jan 2009
    Posts
    913

    How to calculate simple interest in java ?

    Hi,
    I am new to programming language. I recently started learning java language. Yesterday our sir has given us assignment in which one program is there like write program to calculate simple interest in java. I tried various method but I unable to write that program. That's why I asked this question on this forum. So if you have any idea about this please help me.Thanks in advanced.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to calculate simple interest in java ?

    Hi,
    Rather than writing whole program I just give you logic behind it. You have to write that program on your own, this will help you solving other program quickly. You have to use following formula to calculate simple interest :

    SimpleInterest=PrincipleAmount*RateOfInterest*NumberOfYears

    In your program you have to take all three value from user then calculate it to get the Simple Interest.
    I think this will help you.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to calculate simple interest in java ?

    I just given you esy program to calculate simple interest. Tried to comile it in your computer and let me know whether it works or not.


    Code:
       
          int main()
      
          {
    
          int a,b,count1;
     
          float c,simp;
    
           
     
          count1=1;
    
          while(count1<=3)
    
          {
     
          printf("\n enter values of a,b,andc");
    
          scanf("%d %d %f",&a, &b, &c);
    
          simp=(float)a * (float)b * c / 100;
    
          printf("simple interest = %f rs.",simp);
      
          count1=count1+1;
    
          }
      
           
    
          return(0);
    
          }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to calculate simple interest in java ?

    This is program to calculate simple interest just go through it



    Code:
    public class SimpleInterest{
    
    
    float princ,IR, NOY;
    
    public void setPrincipal(float princ){
    this.princ = princ;
    }
    
    public void setIntRate(float IR){
    this.IR = IR;
    }
    
    public void setNumOfYears(float NOY){
    this.NOY = NOY;
    }
    
    public float calculateSimpleInterest(){
    
    return (this.princ * this.IR * this.NOY) /100;
    
    }
    
    public static void main(String argv[]){
    
    float princ,IR, NOY;
    
    SimpleInterest Obj1 = new SimpleInterest();
    
    princ = Float.parseFloat(argv[0]);
    IR = Float.parseFloat(argv[1]);
    NOY = Float.parseFloat(argv[2]);
    
    Obj1.setPrincipal(princ);
    Obj1.setIntRate(IR);
    Obj1.setNumOfYears(NOY);
    
    System.out.println ("Principal amount = "+princ);
    System.out.println (" Rate of interest = "+IR);
    System.out.println ("Number of Years = "+NOY);
    
    System.out.println ("Simple Interest Amount is = "+Obj1.calculateSimpleInterest());
    }
    
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to calculate simple interest in java ?

    I write program to calculate simple interest using some value try to understand each step.


    Code:
    class simpleInterest
    {
    public static void main(String args[])
    {
    float princ, noy, roy, simpleInt;
    princ = 20000;
    noy= 8;
    roy = 9.3F;
    simpleInt = princ * noy * roy ;
    simpleInt = simpleInt / 100 ;
    System.out.println("\n Simple Interest on a principle of "+princ+" is "+simpleInt+" at the rate of "+roy+" for a period of "+noy);
    
    }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: How to calculate simple interest in java ?

    I think this is the simplest program to calculate simple interest.


    Code:
    import java.util.Scanner;
    class simpleinterest
    {
    Scanner obj=new Scanner(System.in);
    double pr,r,t,x,y,z;
    void interest( double princ,double roi,double year)
    {
    y=(princ*roi*year)/100;
    System.out.println("simple interest :"+y);
    }
    void interest(double princ, double roi,double year,int x) 
    {
    double d=year/x;
    double l=1+(roi/100);
    z=princ*(Math.pow(l,d)-1);
    System.out.println("compound interest:"+z);
    }
    public static void main (String args[])
    {
    simpleinterest obj1=new simpleinterest();
    simpleinterest obj2=new simpleinterest();
    obj1.interest(200000,20,32);
    obj2.interest(200000,20,32,7);
    }
    }

  7. #7
    Join Date
    Dec 2011
    Posts
    1

    Affection Re: How to calculate simple interest in java ?

    can we use
    int long princ.=10,000????

  8. #8
    Join Date
    Jan 2006
    Posts
    605

    Re: How to calculate simple interest in java ?

    Quote Originally Posted by balls View Post
    can we use
    int long princ.=10,000????
    If you have an int object, you should easily be able to convert that to a long and then the same number back to an int.

    Code:
    int x = 10000;
    System.out.println(x); // 10000
    long y = (long)x;
    System.out.println(y); // 10000
    int z = (int)y;
    System.out.println(z); // 10000

Similar Threads

  1. I am looking for a formula to calculate compound interest in Excel
    By Corey Dunnett in forum MS Office Support
    Replies: 3
    Last Post: 03-02-2012, 06:05 PM
  2. Calculate Earnings Before Interest and Tax
    By brynhildur in forum Education Career and Job Discussions
    Replies: 3
    Last Post: 18-11-2010, 02:51 PM
  3. How to Calculate Process Time in Java?
    By Bhardwaj in forum Software Development
    Replies: 3
    Last Post: 08-12-2009, 12:25 PM
  4. How to calculate area of Circle in Java?
    By Aandaleeb in forum Software Development
    Replies: 4
    Last Post: 28-11-2009, 09:43 PM
  5. Need a simple formula to calculate EV and PV seperately
    By CooRa in forum Microsoft Project
    Replies: 2
    Last Post: 17-09-2009, 10:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,046,749.32909 seconds with 17 queries