Q3. A man invests certain sum of money at 5% compound interest for the first year, 8% for the second year and 10% for the third year. Write a program in java to calculate the amount after three years, taking the sum as an input.

 

Assignment Method

BlueJ Method

Command Line Argument Method

class if_Pg_106_Q3_as

{

    public static void main(String args[])

    {

        double P;

        P=5000;

        double r1=5.0,r2=8,r3=10;

        double A;

        A=P*(1+(r1/100))*(1+(r2/100))*(1+(r3/100));

        System.out.println("Amount ="+A);

    }

}

class if_Pg_106_Q3_bj

{

    public static void main(double P)

    {

        double r1=5.0,r2=8,r3=10;

        double A;

        A=P*(1+(r1/100))*(1+(r2/100))*(1+(r3/100));

        System.out.println("Amount ="+A);

    }

}

class if_Pg_106_Q3_cl

{

    public static void main(String args[])

    {

        double P;        P=Double.parseDouble(args[0]);

        double r1=5.0,r2=8,r3=10;

        double A;

        A=P*(1+(r1/100))*(1+(r2/100))*(1+(r3/100));

        System.out.println("Amount ="+A);

    }

}

 

Input Stream Reader Method

Scanner Method

import java.io.*;

class if_Pg_106_Q3_isr

{

    public static void main(String args[])throws IOException

    {

        InputStreamReader  isr = new InputStreamReader(System.in);

        BufferedReader in = new BufferedReader(isr);

        double P;

        System.out.print("Enter Principle:");

        P=Double.parseDouble(in.readLine());

        double r1=5.0,r2=8,r3=10;

        double A;

        A=P*(1+(r1/100))*(1+(r2/100))*(1+(r3/100));

        System.out.println("Amount ="+A);

    }

}

import java.util.*;

class if_Pg_106_Q3_scn

{

    public static void main(String args[])

    {

        Scanner in = new Scanner(System.in);

        double P;

        System.out.print("Enter Principle:");

        P=in.nextDouble();

        double r1=5.0,r2=8,r3=10;

        double A;

        A=P*(1+(r1/100))*(1+(r2/100))*(1+(r3/100));

        System.out.println("Amount ="+A);

    }

}