/**

 *

 * To test Interest Computer class

 * @author Ahmad Mobasseri

 */

import java.text.*;

public class InterestTester

{ 

   public static void main(String[] args)

   { 

         DecimalFormat df = new DecimalFormat("0.00");

        

         // Test Default Constructor and Getters

         InterestComputer testSetValues = new InterestComputer();

         double amount = testSetValues.interestCompute();

         System.out.println("Compond amount for $" + testSetValues.getPrinciple() + " principle, with "

                     + testSetValues.getInterestRate() + " % interest in " + testSetValues.getTime() +

                     " year is: $" + df.format(amount));

 

// NOTE: since called class (InterestComputer) used run time exceptions => then we have option

// to use or not to use 'try-catch'   

        

         try

         {

               // Test Setters              

//             testSetValues.setPrinciple(-120);      NOTE: this causes following lines in 'try' blk to

//                                                                              NOT execute.

               testSetValues.setPrinciple(120);

               testSetValues.setInterestRate(10);

               testSetValues.setTime(1.5);

               testSetValues.setPrinciple(-120);

         }

         catch (Exception e)                          // On Negative number

         {

               System.out.println("Error: " + e.getMessage());

         }

         amount = testSetValues.interestCompute();

         System.out.println("Compond amount for $" + testSetValues.getPrinciple() + " principle, with "

                     + testSetValues.getInterestRate() + " % interest in " + testSetValues.getTime() +

                     " year is: $" + df.format(amount));

        

         try

         {

               // Test Constructor

               InterestComputer testPassValues = new InterestComputer(150, 0, 2);

               amount = testPassValues.interestCompute();

               System.out.println("Compond amount for $" + testPassValues.getPrinciple() +

                     " principle, with " + testPassValues.getInterestRate() + " % interest in " +

                     testPassValues.getTime() + " year is: $" + df.format(amount));

               InterestComputer testNegativeValues = new InterestComputer(-150, 1, 2);

         }

         catch (Exception e)                          // On Negative number

         {

               System.out.println("Error: " + e.getMessage());

         }

   }

}

 

/**  OutPut of Test

Compond amount for $100.0 principle, with 5.0 % interest in 1.0 year is: $105.00

Error: Negative number for Principe, is invalid

Compond amount for $120.0 principle, with 10.0 % interest in 1.5 year is: $138.44

Compond amount for $150.0 principle, with 0.0 % interest in 2.0 year is: $150.00

Error: Negative numbers are invalid  **/