when u borrow money to buy a house,a car,or for some other purposes,then u typic
ID: 3545718 • Letter: W
Question
when u borrow money to buy a house,a car,or for some other purposes,then u typically repay it by making periodic payments.Suppose that the loan amount is L,r is the interest rate per year,m is the number of payments in a year,and the loan is for t years.Suppose that i = (r / m) and r is in decimal.Then the periodic payment is: R = Li / 1 - (1 +i) ^ -mt you can also calculate the unpaid loan balance after making certain payments.For example,the unpaid balance after making k payment s is: L' = R [1 - (1 + i) ^ -(mt - k) / i ] where R is the periodic payment.(Note that if the payments are monthly , then m = 12) write a program that prompts the user to input the values of L,r,m,t and k. The program then outputs the appropriate parameters,to calculate the periodic payments and the unpaid balance after certain payments.Make the program menu driven and use a loop so that the user can repeat the program for different values. in addition to the two function requirements presented in the text (periodicPayment and unpaidBalance),your program should contains additional functions as necessary,to implement the menu driven requirement.Consider function to display the menu(showMenu)and output the loan parameters(outputLoanVars) Note: don't use global variables
Explanation / Answer
import java.util.Scanner;
import java.lang.Math.*;
public class Sample
{
public static void main(String args[])
{
ProcessCreation pc=new ProcessCreation();
pc.showMenu();
}
}
class ProcessCreation
{
public void showMenu()
{
int ch;
System.out.println("Please enter your choice from the following:");
System.out.println("1. No payments made so far");
System.out.println("2. A few payments have been made already");
System.out.println("3.Exit");
Scanner in=new Scanner(System.in);
ch=in.nextInt();
switch(ch)
{
case 1: periodicPayment();
System.out.print("The periodic payment is:");
case 2:
unpaidBalance();
System.out.print("The unpaid balance is:");
case 3: break;
}
}
public void periodicPayment()
{
int L,m,t;
float r;
double R,i,y, x , result;
Scanner in=new Scanner(System.in);
System.out.println("Please enter the total loan amount:");
L=in.nextInt();
System.out.println("The total loan amount you entered is:"+L);
System.out.println("Please enter the total number of payments:");
m=in.nextInt();
System.out.println("The total number of payments is:"+m);
System.out.println("Please enter the total number of years:");
t=in.nextInt();
System.out.println("The total number of years is:"+t);
System.out.println("Please enter the interest rate:");
r=in.nextFloat();
System.out.println("The interest rate is:"+r);
i=(r/m);
x=i+1;
y=m*t;
result= Math.pow(x,y);
R=(L*i)/(1-(1/result));
System.out.println(""+R);
}
public void unpaidBalance()
{
int L,a, m,t, k;
float r;
double R,i,y, x ,result,x1, L1;
Scanner in=new Scanner(System.in);
System.out.println("Please enter the total loan amount:");
L=in.nextInt();
System.out.println("The total loan amount you entered is:"+L);
System.out.println("Please enter the total number of payments:");
m=in.nextInt();
System.out.println("The total number of payments is:"+m);
System.out.println("Please enter the total number of years:");
t=in.nextInt();
System.out.println("The total number of years is:"+t);
System.out.println("Please enter the number of payments made so far:");
k=in.nextInt();
System.out.println("The number of payments made so far is:"+k);
System.out.println("Please enter the interest rate:");
r=in.nextFloat();
System.out.println("The number of payments made so far is:"+r);
i=(r/m);
x=i+1;
y=m*t;
result= Math.pow(x,y);
R=(L*i)/(1-(1/result));
x1=Math.pow((1+i), (1/(m*t-k)));
L1=R*(1-x1)/i;
System.out.println("" +L1);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.