Sunday, 17 July 2011

Write a program to calculate compound interest using inheritance

public class Power
{
double pr=1;
public double pow(double no,int p)
{
while(p>0)
{
pr=pr*no;
p--;
}
return pr;
}
}
import java.io.*;
public class Ci extends Power
{
int p,t;
double r,ans;
public void input()
throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the principal");
p=Integer.parseInt(br.readLine());
System.out.println("enter the rate of interest");
r=Double.parseDouble(br.readLine());
System.out.println("Enter the time");
t=Integer.parseInt(br.readLine());
}
public void output()
{
System.out.println("the compound interest is:"+ans);
}
public void cal()
{
double h=1.0+r/100;

double res=pow(h,t);

ans=p*res-p;
}
}

import java.io.*;
public class Cimain
{
public static void main(String[] arg)
throws IOException
{
Ci c=new Ci();
c.input();
c.cal();
c.output();
}
}

No comments:

Post a Comment

 

About The Author


I am a B.Tech Computer Science Student. I love Programming and blogging. I am Oracle certified Java Professional. Read More
Indian Blogger

Teachers Jobs

Footer 3

Twitter Facebook RSS YouTube Google
​

All Rights Reserved ©Sun Java Masters 2013