•
•
•
•
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
A program similar to ComputeMortgage.java utilizing a mathematical formula and multiple methods to calculate a loan payment.
package loancalculation; public class LoanCalculation { // Main method public static void main(String[] args) { double annualInterestRate; int numOfYears; double loanAmount; // Enter monthly interest rate System.out.println( "Enter yearly interest rate, for example 8.25: "); annualInterestRate = MyInput.readDouble(); // Obtain monthly interest rate double monthlyInterestRate = annualInterestRate/1200; // Enter number of years System.out.println( "Enter number of years as an integer, for example 5: "); numOfYears = MyInput.readInt(); // Enter loan amount System.out.println("Enter loan amount, for example 120000.95: "); loanAmount = MyInput.readDouble(); // Calculate payment double monthlyPayment = loanAmount*monthlyInterestRate/ (1 - (Math.pow(1/(1 + monthlyInterestRate), numOfYears*12))); double totalPayment = monthlyPayment*numOfYears*12; // Display results System.out.println("The monthly payment is " + monthlyPayment); System.out.println("The total payment is " + totalPayment); // Pause System.out.println("Press Ctrl+C to close this window ..."); MyInput.readInt(); } }
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)