import java.util.Scanner;
public class Savings{
/**
* the following program will calculate both monthly savings and total savings for a given number of months using
* compound interest for any given monthly salary, rate of interest and
* percentage of salary that will get spent monthly.
*/
public static void main(String[] args){
Scanner in = new Scanner(System.in);
//Enter the monthly salary (50000 in your case)
System.out.println("Enter your Salary recieved per month ");
int salary = in.nextInt();
//Enter the fraction of the salary that would be spent(14 in your case)
System.out.println("Enter the percentage of your salary you would be spending");
int exp = in.nextInt();
double expenditure = (double)(exp/100.0);
//Enter the rate of interest (4 in your case)
System.out.println("Enter the rate of interest per year you would recieve when you store your money in the bank");
double rateOfInterest = in.nextDouble();
rateOfInterest /= 100.0;
//savings per month is just income - expenditure
double monthlySavings = (double)(salary*(1-expenditure));
System.out.println("Your Monthly Savings are = "+monthlySavings+" of your respective currency");
double totalSavings = 0;
System.out.println("Enter the number of months you wish to follow the same savings plan for");
int numberOfMonths = in.nextInt();
//monthly compounding is used
//to use quarterly compounding use the first comment inside the loop and comment out line number 32
//to use semi-annual compounding use the second comment inside the loop and comment out line number 32
for(int i= 1;i<=numberOfMonths;i++){
totalSavings += monthlySavings;
double interest = (totalSavings*rateOfInterest)/12.0;
/*if(i%3==0){
double interest = (totalSavings*rateOfInterest)/4.0;
}*/
/*if(i%6==0){
double interest = (totalSavings*rateOfInterest)/2.0;
}*/
totalSavings += interest;
}
System.out.println("Your total savings will be "+totalSavings+" of your respective currency");
in.close();
}
}
Copy the above code in any java compiler and compile and run it.
Hope it was Helpful