A simple demonstration of how MyInput.class can be used to input data from the keyboard. Computation is then done to compute the interest rate on a mortage.

package compmortgage;
public class CompMortgage
// Main method
public static void main(String[] args)
double annualInterestRate;
int numOfYears;
double loanAmount;
String prompt = "\n\nEnter yearly interest rate, for example 8.25 ";
// Enter monthly interest rate
annualInterestRate = MyInput.readDouble();
while (annualInterestRate > 0) {
// Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate/1200;
// Enter number of years
"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);
// Enter monthly interest rate
System.out.println(prompt + "(0 to exit) ");
annualInterestRate = MyInput.readDouble();

While pursuing a Computer Science degree, I founded DaniWeb.com, an online community for developers and IT professionals. I coded the backend platform from the ground up and I also do all of the advertising sales and SEO. I'm a super-geeky programmer with a passion for Internet marketing.

12 Years
Discussion Span
Last Post by holmes008
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.