# Write a java program to calculate interest.

Write a  program to calculate an amount of the account holders based on the below-mentioned prototype:
1. Read account details from the User. The details would include id, DOB (date of birth) and the amount in the given order. The datatype for id is the string, DOB is string and amount is the integer.
2. You decide to build two hashmaps. The first hashmap contains employee id as key and DOB as value, and the second hashmap contains same employee ids as key and amount as value.
3. The rate of interest as on 01/01/2015:
a. If the age greater than or equal to 60 then the interest rate is 10% of Amount.
b.If the ageless then to 60 and greater than or equal to 30 then the interest rate is 7% of Amount.
v. If the ageless then to 30 interest rate is 4% of Amount.
4. Revised Amount= principle Amount + interest rate.
Input and Output Format:
Input consists of account details. The first number indicates the size of the account. The next three values indicate the user id, DOB, and amount. The Employee DOB format is “dd-mm-yyyy”
The output consists of the user id and the amount for each user one in a line.
Refer sample output for formatting specifications.

Sample Input 1:
4
SBI-1010
20-01-1987
10000
SBI-1011
03-08-1980
15000
SBI-1012
05-11-1975
20000
SBI-1013
02-12-1950
30000
Sample Output 1:
SBI-1010:10400
SBI-1011:16050
SBI-1012:21400
SBI-1013:33000

## Interest Calculation in Java.

```import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s = Integer.parseInt(sc.nextLine());
HashMap<String, String> hm = new HashMap<String, String>();
HashMap<String, Integer> hm1 = new HashMap<String, Integer>();
for (int i = 0; i < s; i++) {
String id = sc.nextLine();
hm.put(id, sc.nextLine());
hm1.put(id, Integer.parseInt(sc.nextLine()));
}
TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
tm = display(hm, hm1);
Iterator<String> it = tm.keySet().iterator();
while (it.hasNext()) {
String n = it.next();
int fac = tm.get(n);
System.out.println(n + ":" + fac);
}
}

public static TreeMap<String, Integer> display(HashMap<String, String> hm,
HashMap<String, Integer> hm1) {
int year = 0, amount = 0;
double dis = 0;
String now = "01/01/2015";
TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
Iterator<String> it = hm.keySet().iterator();
while (it.hasNext()) {
String id = it.next();
String dor = hm.get(id);
amount = hm1.get(id);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");
try {
Date d = sdf.parse(dor);
Date d1 = sdf1.parse(now);
sdf.setLenient(false);
int y = d.getYear();
int y1 = d1.getYear();
int m = d.getMonth();
int m1 = d1.getMonth();
int day = d.getDay();
int day1 = d1.getDay();
year = y1 - y;
if (m > m1)
year--;
else if (m == m1) {
if (day < day1)
year--;
}
if (year >= 60)
dis = 0.1 * amount + amount;
else if (year < 60 && year >= 30)
dis = 0.07 * amount + amount;
else
dis = 0.04 * amount + amount;
tm.put(id, (int) dis);
} catch (Exception e) {
e.printStackTrace();
}
}
return tm;
}

}
```