User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,988 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,492 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Sep 20th, 2004
Views: 3,439
A program similar to ComputeMortgage.java utilizing a mathematical formula and multiple methods to calculate a loan payment.
java Syntax | 4 stars
  1. package loancalculation;
  2. public class LoanCalculation
  3. {
  4. // Main method
  5. public static void main(String[] args)
  6. {
  7. double annualInterestRate;
  8. int numOfYears;
  9. double loanAmount;
  10. // Enter monthly interest rate
  11. System.out.println(
  12. "Enter yearly interest rate, for example 8.25: ");
  13. annualInterestRate = MyInput.readDouble();
  14. // Obtain monthly interest rate
  15. double monthlyInterestRate = annualInterestRate/1200;
  16. // Enter number of years
  17. System.out.println(
  18. "Enter number of years as an integer, for example 5: ");
  19. numOfYears = MyInput.readInt();
  20. // Enter loan amount
  21. System.out.println("Enter loan amount, for example 120000.95: ");
  22. loanAmount = MyInput.readDouble();
  23. // Calculate payment
  24. double monthlyPayment = loanAmount*monthlyInterestRate/
  25. (1 - (Math.pow(1/(1 + monthlyInterestRate), numOfYears*12)));
  26. double totalPayment = monthlyPayment*numOfYears*12;
  27. // Display results
  28. System.out.println("The monthly payment is " + monthlyPayment);
  29. System.out.println("The total payment is " + totalPayment);
  30. // Pause
  31. System.out.println("Press Ctrl+C to close this window ...");
  32. MyInput.readInt();
  33. }
  34. }
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 9:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC