Q1. Mr. Shyam Lal Agarwal invests certain sum at 5% per annum compound Interest for three Years. Write a program in java to calculate:
(a) the interest for the first year. (b) the interest for the second year (c) the amount after three years. Take the sum as input from the user.
Assignment Method |
BlueJ Method |
Command Line Argument Method |
class if_Pg_106_Q1_as { public static void main(String args[]) { double p; p=5000; double r=5.0; double i1,a1,i2,a2,i3,a3; i1=(p*r*1)/100; a1=p+i1; i2=(a1*r*1)/100; a2=a1+i2; i3=(a2*r*1)/100; a3=a2+i3; System.out.println("Interest for first year ="+i1); System.out.println("Interest for second year ="+i2); System.out.println("Amount ="+a3); } } |
class if_Pg_106_Q1_bj { public static void main(double p) { double r=5.0; double i1,a1,i2,a2,i3,a3; i1=(p*r*1)/100; a1=p+i1; i2=(a1*r*1)/100; a2=a1+i2; i3=(a2*r*1)/100; a3=a2+i3; System.out.println("Interest for first year ="+i1); System.out.println("Interest for second year ="+i2); System.out.println("Amount ="+a3); } } |
class if_Pg_106_Q1_cl { public static void main(String args[]) { double p; p=Double.parseDouble(args[0]); double r=5.0; double i1,a1,i2,a2,i3,a3; i1=(p*r*1)/100; a1=p+i1; i2=(a1*r*1)/100; a2=a1+i2; i3=(a2*r*1)/100; a3=a2+i3; System.out.println("Interest for first year ="+i1); System.out.println("Interest for second year ="+i2); System.out.println("Amount ="+a3); } } |
Input Stream Reader Method |
Scanner Method |
import java.io.*; class if_Pg_106_Q1_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 r=5.0; double i1,a1,i2,a2,i3,a3; i1=(p*r*1)/100; a1=p+i1; i2=(a1*r*1)/100; a2=a1+i2; i3=(a2*r*1)/100; a3=a2+i3; System.out.println("Interest for first year ="+i1); System.out.println("Interest for second year ="+i2); System.out.println("Amount ="+a3); } } |
import java.util.*; class if_Pg_106_Q1_scn { public static void main(String args[]) { Scanner in=new Scanner(System.in); double p; System.out.print("Enter Principle:"); p=in.nextDouble(); double r=5.0; double i1,a1,i2,a2,i3,a3; i1=(p*r*1)/100; a1=p+i1; i2=(a1*r*1)/100; a2=a1+i2; i3=(a2*r*1)/100; a3=a2+i3; System.out.println("Interest for first year ="+i1); System.out.println("Interest for second year ="+i2); System.out.println("Amount ="+a3); } } |