Monday 30 October 2017

java - loan payment calculator, how to implement multiple methods. Trouble developing method to interact with main method

The idea of this assignment is to have multiple methods
interact with each other. I am asking the user for loan amount, interest rate and
duration of loan. Then the program is supposed to have one method that calculates the
monthly rate, one method that calculates and returns the monthly payment and a method to
print the loan statement (amt borrowed,annual interest rate, number of months, and the
monthly payment).




I am not receiving
any errors in the editor but my program just asks for the three inputs from the user and
does not print the loan statement. Any
suggestions?



public class CarLoan
{

/**
* @param args the command line
arguments
*/
public static void main(String[] args) {
//
declare variables for main method

double loanAmount;//double value
loan amount
double annualInterestRate;//double value interest
rate
int numberOfMonths;//int value for number of months
double
monthlyPayment;

Scanner keyboard = new
Scanner(System.in);

System.out.println("Please enter the amount of
your loan.");
loanAmount =
keyboard.nextDouble();


System.out.println("Please enter
the annual interest rate as a decimal. Ex. 7.5% = .075");
annualInterestRate
= keyboard.nextDouble();

System.out.println("Please enter the
number of months you have to pay back your loan.");
numberOfMonths =
keyboard.nextInt();

}

public static double
calcMonthlyInterestRate(double annualInterestRate){
double
monthlyInterestRate;

monthlyInterestRate =
(annualInterestRate/12);
return monthlyInterestRate;
}//end method
CalcMonthlyInterestRate

public static double
calcMonthlyPayment(double monthlyInterestRate, double loanAmount, int numberOfMonths
){
double monthlyPayment;
double calcMonthlyPayment;

calcMonthlyPayment =
(monthlyInterestRate*loanAmount)/(1-(1+monthlyInterestRate)-numberOfMonths);

return monthlyPayment = calcMonthlyPayment;
}//end method
CalcMonthlyPayment


public static void loanStatment
(double loanAmount, double annualInterestRate, intnumberOfMonths, double
monthlyPayment){
System.out.println("Your loan amount is "
+loanAmount);
System.out.println(annualInterestRate);

System.out.println(numberOfMonths);

System.out.println(monthlyPayment);
}

}//end main
method



}//end main
method


I am not sure
if some of my code is still redundant.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...