Tuesday, 29 August 2017

how to create interface in java program

W.A.P that create interface on that you declare one method interest(p,r,n) then create two class simple and compound that implements interest and find simple and compound interest.

Program

interface Bank
{
          void interest(int p,int r,int n);
}
class SimpleInt implements Bank
{
          public void interest(int p,int r,int n)
          {
                   System.out.println("simple interest is:\t"+((p*r*n)/100));
          }
}
class CompoundInt implements Bank
{
          public void interest(int p,int r,int n)
          {
                   System.out.println("Compound interest is:\t"+p*(Math.pow((1+(r/100)),n)));
          }
}
class interest
{
          public static void main(String args[])
          {
                   SimpleInt s=new SimpleInt();
                   s.interest(10,100,2);
                   CompoundInt c=new CompoundInt();
                   c.interest(10,100,2);
          }

}

Output

 create interface core Java

0 comments:

Post a Comment