Interest Calculator Program in Java

Interest Calculator based on core java  Program....  See Below following code....


 Package : basePackage, exceptionpackage, otherPackage

otherPackage
      -----à  1. Test.java

----------------------------------------------


package otherPackage;

import java.util.*;
import basePackage.*;
public class Test
{
                public static void main(String[] args)
                {
                                new Test();
                                Scanner s=new Scanner(System.in);
                                System.out.println("Select the option:");
                                System.out.println("1. Interest Calculator-SB");
                                System.out.println("2. Interest Calculator-FD");
                                System.out.println("3. Interest Calculator-RD");
                                System.out.println("4. Exit");
                                int option=s.nextInt();
                                switch(option)
                                {
                                                case 1:
                                                SBAccount sb=new SBAccount();
                                                System.out.println("Interest gained: Rs."+sb.calculateInterest());
                                                break;
                                                case 2:
                                                FDAccount fd=new FDAccount();
                                                System.out.println("Interest gained: Rs."+fd.calculateInterest());
                                                break;
                                                case 3:
                                                RDAccount rd=new RDAccount();
                                                System.out.println("Interest gained: Rs."+rd.calculateInterest());
                                                break;
                                                case 4:
                                                System.exit(0);
                                                break;
                                }
                }
}

exceptionpackage             -----à 1. NegativeException.java
----------------------------------------------------------
package exceptionpackage;

public class NegativeException extends Exception
{
                public String ExceptionMessage()
                {
                                return("Value cannot be zero/Value cannot be negative");
                }
}

basePackage        ------------ à1. Account.java
------------------------------------ ----------------
package basePackage;

public abstract class Account
{
                double interestrate;
                double amount;
                public abstract double calculateInterest();
}
 basePackage        --------------- à2. FDAccount.java
----------------------------------------------------
package basePackage;

import java.util.*;

import exceptionpackage.NegativeException;


public class FDAccount extends Account
{
                double interestrate;
                double amount;
                int noofdays;
                int ageOfAcHolder;
                double intgained;
                Scanner s=new Scanner(System.in);
                public double calculateInterest()
                {              
                                System.out.println("Enter the FD Amount:");
                                amount=s.nextDouble();   
                                System.out.println("Enter the no of days:");
                                noofdays=s.nextInt();         
                                System.out.println("Enter your age:");
                                ageOfAcHolder=s.nextInt();
                                int check=0;
                                if(amount<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else if(noofdays<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else if(ageOfAcHolder<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else
                                {
                                                if(amount<10000000)
                                                {
                                                                if((noofdays>=7 && noofdays<=14) && (ageOfAcHolder<=60))
                                                                {
                                                                                check=1;
                                                                }
                                                                if((noofdays>=15 && noofdays<=29)&& (ageOfAcHolder<=60))
                                                                {
                                                                                check=2;              
                                                                }
                                                                if((noofdays>=30 && noofdays<=44)&& (ageOfAcHolder<=60))
                                                                {
                                                                                check=3;              
                                                                }
                                                                if((noofdays>=45 && noofdays<=60) &&(ageOfAcHolder<=60))
                                                                {
                                                                                check=4;              
                                                                }
                                                                if((noofdays>=61 && noofdays<=184) &&(ageOfAcHolder<=60))
                                                                {
                                                                                check=5;                              
                                                                }
                                                                if((noofdays>=185 && noofdays<=365) &&(ageOfAcHolder<=60))
                                                                {
                                                                                check=6;                              
                                                                }


                                                                if((noofdays>=7 && noofdays<=14) && (ageOfAcHolder>60))
                                                                {
                                                                                check=7;
                                                                }
                                                                if((noofdays>=15 && noofdays<=29)&& (ageOfAcHolder>60))
                                                                {
                                                                                check=8;              
                                                                }
                                                                if((noofdays>=30 && noofdays<=44)&& (ageOfAcHolder>60))
                                                                {
                                                                                check=9;              
                                                                }
                                                                if((noofdays>=45 && noofdays<=60) &&(ageOfAcHolder>60))
                                                                {
                                                                                check=10;            
                                                                }
                                                                if((noofdays>=61 && noofdays<=184) &&(ageOfAcHolder>60))
                                                                {
                                                                                check=11;                            
                                                                }
                                                                if((noofdays>=185 && noofdays<=365) &&(ageOfAcHolder>60))
                                                                {
                                                                                check=12;                            
                                                                }
                                                               
                                                }
                                                if(amount>10000000)
                                                {
                                                               
                                                                if((noofdays>=7 && noofdays<=14))
                                                                {
                                                                                check=13;
                                                                }
                                                                if((noofdays>=15 && noofdays<=29))
                                                                {
                                                                                check=14;            
                                                                }
                                                                if((noofdays>=30 && noofdays<=44))
                                                                {
                                                                                check=15;            
                                                                }
                                                                if((noofdays>=45 && noofdays<=60))
                                                                {
                                                                                check=16;            
                                                                }
                                                                if((noofdays>=61 && noofdays<=184))
                                                                {
                                                                                check=17;                            
                                                                }
                                                                if((noofdays>=185 && noofdays<=365))
                                                                {
                                                                                check=18;                            
                                                                }
                                                }
                                               
                                                switch(check)
                                                {
                                                                case 1:
                                                                intgained=((amount*4.50)/100);
                                                                break;

                                                                case 2:
                                                                intgained=((amount*4.75)/100);
                                                                break;

                                                                case 3:
                                                                intgained=((amount*5.50)/100);
                                                                break;

                                                                case 4:
                                                                intgained=((amount*7)/100);
                                                                break;
                                                               
                                                                case 5:
                                                                intgained=((amount*7.50)/100);
                                                                break;
                                                               
                                                                case 6:
                                                                intgained=((amount*8.00)/100);
                                                                break;

                                                                case 7:
                                                                intgained=((amount*5.00)/100);
                                                                break;

                                                                case 8:
                                                                intgained=((amount*5.25)/100);
                                                                break;

                                                                case 9:
                                                                intgained=((amount*6.00)/100);
                                                                break;
                                                               
                                                                case 10:
                                                                intgained=((amount*7.50)/100);
                                                                break;

                                                                case 11:
                                                                intgained=((amount*8.00)/100);
                                                                break;

                                                                case 12:
                                                                intgained=((amount*8.50)/100);
                                                                break;

                                                                case 13:
                                                                intgained=((amount*6.50)/100);
                                                                break;

                                                                case 14:
                                                                intgained=((amount*6.75)/100);
                                                                break;

                                                                case 15:
                                                                intgained=((amount*6.75)/100);
                                                                break;
                                                               
                                                                case 16:
                                                                intgained=((amount*8)/100);
                                                                break;

                                                                case 17:
                                                                intgained=((amount*8.50)/100);
                                                                break;

                                                                case 18:
                                                                intgained=((amount*10.00)/100);
                                                                break;
                                                }
                                                               
                                }
                               
                                return(intgained);
                }
}
basePackage             ----------- à2. RDAccount.java
----------------------------------------------------
package basePackage;
import java.util.*;

import exceptionpackage.NegativeException;
public class RDAccount extends Account
{
                double interestrate;
                double amount;
                int noofmonths;
                int ageOfAcHolder;
                double intgained;
                Scanner s=new Scanner(System.in);
                public double calculateInterest()
                {
                                System.out.println("Enter the RD Amount:");
                                amount=s.nextDouble();   
                                System.out.println("Enter the no of months:");
                                noofmonths=s.nextInt();    
                                System.out.println("Enter your age:");
                                ageOfAcHolder=s.nextInt();
                                int check=0;
                                if(amount<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else if(noofmonths<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else if(ageOfAcHolder<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else
                                {
                                                if(ageOfAcHolder<60)
                                                {
                                                                                               
                                                                if((noofmonths>0) && (noofmonths<=6))
                                                                {
                                                                                check=1;
                                                                }
                                                                if((noofmonths>6) && (noofmonths<=9))
                                                                {
                                                                                check=2;
                                                                }
                                                                if((noofmonths>9) && (noofmonths<=12))
                                                                {
                                                                                check=2;              
                                                                }
                                                                if((noofmonths>12) && (noofmonths<=15))
                                                                {
                                                                                check=4;              
                                                                }
                                                                if((noofmonths>15) && (noofmonths<=18))
                                                                {
                                                                                check=5;              
                                                                }
                                                                if((noofmonths>18) && (noofmonths<=21))
                                                                {
                                                                                check=6;                              
                                                                }
                                                               
                                                }
                               
                                                if(ageOfAcHolder>=60)
                                                {
                                                                if((noofmonths>0) && (noofmonths<=6))
                                                                {
                                                                                check=7;
                                                                }
                                                                if((noofmonths>6) && (noofmonths<=9))
                                                                {
                                                                                check=8;
                                                                }
                                                                if((noofmonths>9) && (noofmonths<=12))
                                                                {
                                                                                check=9;              
                                                                }
                                                                if((noofmonths>12) && (noofmonths<=15))
                                                                {
                                                                                check=10;            
                                                                }
                                                                if((noofmonths>15) && (noofmonths<=18))
                                                                {
                                                                                check=11;            
                                                                }
                                                                if((noofmonths>18) && (noofmonths<=21))
                                                                {
                                                                                check=12;                            
                                                                }
                                                }
                                                switch(check)
                                                {
                                                                case 1:
                                                                intgained=((amount*7.50)/100);
                                                                break;

                                                                case 2:
                                                                intgained=((amount*7.75)/100);
                                                                break;

                                                                case 3:
                                                                intgained=((amount*8.00)/100);
                                                                break;

                                                                case 4:
                                                                intgained=((amount*8.25)/100);
                                                                break;

                                                                case 5:
                                                                intgained=((amount*8.50)/100);
                                                                break;

                                                                case 6:
                                                                intgained=((amount*8.75)/100);
                                                                break;

                                                               
                                                                case 7:
                                                                intgained=((amount*8.00)/100);
                                                                break;

                                                                case 8:
                                                                intgained=((amount*8.25)/100);
                                                                break;

                                                                case 9:
                                                                intgained=((amount*8.50)/100);
                                                                break;

                                                                case 10:
                                                                intgained=((amount*8.75)/100);
                                                                break;

                                                                case 11:
                                                                intgained=((amount*9.00)/100);
                                                                break;

                                                                case 12:
                                                                intgained=((amount*9.25)/100);
                                                                break;                   
                                                                                                               
                                                }
                                }
                               
                               
                                return(intgained);
                                               
                }
}
basePackage          -------------- à4. SBAccount.java
----------------------------------------------------
package basePackage;
import java.util.*;

import exceptionpackage.NegativeException;
public class SBAccount extends Account
{
                double interestrate;
                 double amount;
                Scanner s=new Scanner(System.in);
                 double intgained;
                public double calculateInterest()
                {
                                System.out.println("Enter the average amount in your account");
                                amount=s.nextDouble();   
                                if(amount<=0)
                                {
                                                try
                                                {
                                                                throw new NegativeException();
                                                }
                                                catch(NegativeException ne)
                                                {
                                                                System.out.println(ne.ExceptionMessage());
                                                }
                                }
                                else
                                {
                                                 intgained=((amount*4)/100);
                                }
                               
                                return(intgained);
                               
                }              
                               
}




1 comment: