# Field Manual for Hackers

## Java program to calculate compound Interest

1. import java.util.Scanner;

class Test{

public static void main(String ar[])
{

float p,i,n,t;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Principal");
p=sc.nextFloat();
System.out.println("Enter Interest Rate");
i=sc.nextFloat();
System.out.println("Number of times interest is compounded per year");
n=sc.nextFloat();
System.out.println("Time");
t=sc.nextFloat();

System.out.println("Compound Interest is "+(p*(1+i/n)*t));

}
}

2. import java.util.Scanner;
class CompoundInterest
{
public static void main(String ar[])
{
double Pri,Total,IR,Peryear,Time;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of principal");
Pri=sc.nextDouble();
System.out.println("Enter the value Interest Rate");
IR=sc.nextDouble();
System.out.println("Enter the value of interest is compounded per year");
Peryear=sc.nextDouble();
System.out.println("Enter the value of Time");
Time=sc.nextDouble();
Total=(Pri*(1+IR/Peryear)*Time);
System.out.println("Compound Interest="+Total);

}
}

3. import java.util.Scanner;

public class compoundinterest {

public static void main(String ar[])
{
double Principal,amount,rate,Peryear,Time;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the value of principal");
Principal=scan.nextDouble();
System.out.println("Enter the value Interest Rate");
rate=scan.nextDouble();
System.out.println("Enter the value of interest is compounded per year");
Peryear=scan.nextDouble();
System.out.println("Enter the value of Time");
Time=scan.nextDouble();
amount = (Principal*(1+rate/Peryear)*Time);
System.out.println("the compound interest is : " +amount);

}

}

4. import java.util.Scanner;
class Amount1{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
float p,r,t;
double ci;
System.out.println("enter the value of principle amount");
p=obj.nextFloat();
System.out.println("enter the value of rate ");
r=obj.nextFloat();
System.out.println("enter the value of time");
t=obj.nextFloat();
ci=p*(Math.pow((1+r/100),t));
System.out.println("the valueof calculated compound interest is"+ci);
}

}

5. class CompoundInterest{
public static void main(String ar[]){
int p=Integer.parseInt(ar[0]);
int r=Integer.parseInt(ar[1]);
int n=Integer.parseInt(ar[2]);
int t=Integer.parseInt(ar[3]);
int i=0;
i=p*(1+(r/100))^(t);
System.out.printf("CompoundInterest="+i);
}
}

6. package com.example.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Compound_Int extends Activity {

int P, t, n;
float CI, r;
Button btCI;
EditText etCIp, etCIr, etCIt, etCIn;
TextView tvCI;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.compound);
btCI = findViewById(R.id.btCI);
etCIp = findViewById(R.id.etCIp);
etCIt = findViewById(R.id.etCIt);
etCIr = findViewById(R.id.etCIr);
tvCI = findViewById(R.id.tvCI);

btCI.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
P = Integer.parseInt(etCIp.getText().toString());
r = Integer.parseInt(etCIr.getText().toString());
t = Integer.parseInt(etCIt.getText().toString());
n = Integer.parseInt(etCIn.getText().toString());

CI = (float) (P * (Math.pow(1 + r / n, n * t)));

tvCI.setText("Compound Interest="+CI);
}
});
}
}