# Java Question Set I – Conditional Statements in Java

#### 3. Develop a program, that accepts a deposit amount and calculates the amount of interest earned on the deposited amount in a year. Where, the bank pays:

• flat 4% for deposits of up to Rs.1000
• flat 4.5% per year for deposits of up to Rs.5000
• flat 5% for deposits of more than Rs.5000

Logic of the solution:

1. Declare amount  and intst  as a double type as the user can have an amount of decimal points too.
2. Print a message for the user using System.out.println  and ask the user for a amount
3. Store the amount entered by the user into the variable amount
4. Using if statement check if the amount is less than 1000 then
• Interest will be 4%
5. Otherwise, if it is between 1001 & 5000 then
• Interest will be 4.5%
6. Otherwise
• Interest will be 5% flat
7. While storing the interest calculated in the intst  variable that will be printed finally.
```import java.util.*;
class interest
{
public static void main(String [] arg)
{
Scanner sc = new Scanner(System.in);
double amount,intst;

System.out.println("Enter the amount");
amount=sc.nextDouble();

if(amount<=1000)
intst=amount*(4.0/100)*1;
else if(amount>=1001 && amount<=5000)
intst=amount*(4.5/100)*1;
else
intst=amount*(5/100)*1;

System.out.println("Interest Amount is = "+intst);
}
}```

Output:

Alternative logics that can be applied:

This question can also be solved using the switch conditional statement.

Continue to next page for another question.

January 14th, 2016