diff --git a/IndustrialTrainingProjects/CompoundInterestCalculator.java b/IndustrialTrainingProjects/CompoundInterestCalculator.java new file mode 100644 index 0000000..b0315e3 --- /dev/null +++ b/IndustrialTrainingProjects/CompoundInterestCalculator.java @@ -0,0 +1,56 @@ +// Program to calculate compound interest for the provided principle amount & time by following certain criteria. +// You are builing an interest calculation. Following are the rules: +// 1. If deposit = 1yr : Interest = 5% +// 2. If deposit = Greater than 1 yr and less than 3yr : Interest = 5.5% +// 3. If deposit = Greater than 3 yr : Interest = 6% +// Input from user for Principle Amount & Tenture (time period). +// Output Principle + Interest. + +package IndustrialTrainingProjects; + +import java.util.Scanner; + +public class CompoundInterestCalculator{ + public static void main(String[] args){ + //Declare and initialize the variables + float p , r=0 , t , n = 1; + + Scanner inputScanner = new Scanner(System.in); + + System.out.print("\nEnter a Principle number : "); + p = inputScanner.nextInt(); + + System.out.print("\nEnter a Time period in years : "); + t = inputScanner.nextInt(); + + // checks if time is less than 1 yr + if (t <= 1) { + r = 5; + } + + // checks if time is greater than 1 yr and time is less than 3 yr + else if ((t > 1) && (t <= 3)) { + r = (float) 5.5; + } + + // if both condition is false + else { + r = 6; + } + + //Print the variables and their corresponding values + System.out.println("\nThe entered principle amount is = " + p); + System.out.println("\nThe entered time period is " + t); + System.out.println("\nThe rate of interest is = " + r); + System.out.println("\nThe number of times the interest is compounded is " + n); + findCi(p,r,t,n); + } + + private static void findCi(float p, float r, float t, float n) { + //Calculate the compound interest and the amount + double amount = p * Math.pow(1 + (r / n), n * t); + double cinterest = amount - p; + System.out.println("\nCompound Interest after " + t + " years: " + cinterest); + System.out.println("\nAmount after " + t + " years: " + amount); + } +} \ No newline at end of file diff --git a/IndustrialTrainingProjects/README.MD b/IndustrialTrainingProjects/README.MD index 4d8933b..6dc324e 100644 --- a/IndustrialTrainingProjects/README.MD +++ b/IndustrialTrainingProjects/README.MD @@ -24,4 +24,5 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f |1 | [PrivateConBasic.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConBasic.java) | Program to implement private constructor using the basic method. | |2 | [PrivateConSingleton.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConSingleton.java) | Program to implement private constructor using the Singleton method. | |3 | [EmployeeModelClass.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/EmployeeModelClass.java) | Program to create Model Class, Getters, Setters and display the data. | -|4 | [TwoDimensionalArraySum.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/TwoDimensionalArraySum.java) | Program to sum 2 two dimensional arrays forming a matrix. | \ No newline at end of file +|4 | [TwoDimensionalArraySum.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/TwoDimensionalArraySum.java) | Program to sum 2 two dimensional arrays forming a matrix. | +|5 | [CompoundInterestCalculator.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/CompoundInterestCalculator.java) | Program to calculate compound interest for the provided principle amount & time by following certain criteria. | \ No newline at end of file