Please help me write a java program which output looks like the following (note:
ID: 3630089 • Letter: P
Question
Please help me write a java program which output looks like the following (note: if there is a // it means that I am giving a note and it will not be a part of the output).How much is the loan for? //output
1000 //this is user input
What annual interest rate will the loan be? //output
10 //this is user input. no percentage is necessary even though the 12 really is 12%
how much will you be paying off monthly? //output
100 //user input
Loan 1000.0 10.0 100.0 //output that reads from user input and outputs what the user input
monthly interest is 0.008 // (Actual annual interest determined by user input divided by 12. The output should be rounded to the third decimal digit and should not reveal any more than 3 decimal digits.
payment 1 //output
$8 will go towards interest //the amount of interest payment determined by the user input of how much monthly payment.
$92 will go towards principle //the remainder paying off the principle
you still have $902.00 to pay //actual amount still owed after the payment
payment 2 //second months payment
$7.22 will go towards interest
$92.78 will go towards principle
you still have $809.22 to pay //old principle minus payment towards principle = new principle.
//continue on until the loan is paid off completely.
It will take n months to pay off this loan //this will print when the loan is completely paid off. replace n with the actual amount of months it took for the loan to be paid off.
you paid a total of x dollars in interest payments //this is the total amount of interest payments made over the lifetime of the loan. replace x with the actual amount of interest paid.
please note that this is completely interactive. the user will input how much the loan amount is, the interest payment and a fixed payment they will do each month. the program will do the rest once the user inputs the necessary data.
//also note that if the necessary time to pay off a loan is 3 months, the program should continue to show monthly payments until the end of the 3 months. if it takes 100 months, then it should repeat itself for 100 months. the program shall terminate once the loan is completely paid off.
//there should be 3 methods in this. the main methods and two methods to calculate the number of months to pay off the loan and to calculate interest payments.
//lastly please use four loops only, the scanner console command, but no if else statements unless there is no other possible way to do this. I am only limited to basic things in Java. My current knowledge will not allow any more advanced structures.
Thank you for your time my friends.
Explanation / Answer
please rate - thanks
this is really not the best way to divide the program
import java.util.*;
public class amortization
{public static void main(String [] args)
{double principal, rate, mpay;
int cnt;
Scanner in=new Scanner(System.in);
System.out.print("How much is the loan for? ");
principal=in.nextDouble();
System.out.print("What annual interest rate will the loan be? ");
rate=in.nextDouble();
System.out.print("how much will you be paying off monthly? ");
mpay=in.nextDouble();
rate=rate/100/12;
System.out.printf("Principal: $ %.2f ",principal);
System.out.printf("Monthly Interest Rate: %.3f%% ",rate);
System.out.printf("Monthly Payment: %.2f ",mpay);
System.out.printf("Payment Interest Principal Balance ");
cnt=getTable(principal,mpay,rate);
System.out.println("Total number of months: "+(cnt));
}
public static double getInterest(double principal, double rate)
{return principal*rate;
}
public static int getTable(double principal, double mpay, double rate)
{int cnt;
double totint=0,interest;
for(cnt=1;principal>mpay;cnt++)
{interest=getInterest( principal,rate);
totint+=interest;
System.out.printf("%3d %7.2f %7.2f",cnt,interest,principal);
principal=principal+interest-mpay;
System.out.printf(" %7.2f ",principal);
}
interest=principal*rate;
totint+=interest;
System.out.printf("Final Payment: $%6.2f ",principal+interest);
System.out.printf("Total interest paid $%6.2f ",totint);
return cnt;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.