Solved

# mortgage calculator with GUI

Posted on 2005-05-15
306 Views
how can i modify this code so that i can be within a graphical user interface, must have user input for amount of mortgage. and Allow the user to loop back and enter new data or quit.

//Version 1.1.1 find similar code
//Version 1.2.1 remove unneeded code from program
//Version 1.2.2 rename variables
//Version 1.3.1 explain how the code works in the notes
//Version 1.3.1 compile and enter extra notes

import java.lang.Math;               //Import math class to do the calculations
import java.text.DecimalFormat;     //Import decimal formatting class which will format the numbers

class MortgageMulti2 { //Declare Class, which is also the filename
public static void main(String[] arguments) {
double interest = .0575;  //Interest rate in decimal format
double amount = 200000;  // the principle amount borrowed
double payments = 360;     //Term of loan in months, basically the unmber of payments made over 30 years
double monthlyPymnt = (interest/12);     //Monthly interest rate = 5.75% multiplied by twelve

//By typing 'prinln' i can show my name, my class namne, and the basic output required
//which includes Principal amount, interest rate, and number of payments
System.out.println("Name:         Daniel Gallant");
System.out.println("Assignment:   Week 2 program");
System.out.println("________________________ \n");
//this tells the program to skip a line
System.out.println("Principle       : \$" + amount);
//this reads the principle amount and then displays it
System.out.println("Interest Rate   : " + interest * 100 + "%");
//this calculates the interest rate and puts it in percentage form
System.out.println("# of Payments   : " + payments);
//theis read the payments variable and displays the number of payments

/*This is the original mortgae paymetn formaula which is used to finance the loan itself :
Payments * interest / ( 1 - (1 + interest)^ -number of payments )*/

double payment = (amount * monthlyPymnt) /  (1- Math.pow((1 + monthlyPymnt), -payments));
//this defines the decimal format used in the interest rate, principle, and the monthly payments
DecimalFormat myVar = new DecimalFormat("\$###,##0.00");
String myoutput = myVar.format(payments);
System.out.println("Monthly Payment : " + myoutput + "\n");
// this reads and displays 'monthly payment" and the value of the variable monthly payment after it's calculated

//program originally written by 'Tom Pitts' he can linked to http://www.experts-exchange.com/M_3436866.html
//program code retrieved on april 10th, 2005 at http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21197647.html
// final editing done with help of Sudhakar Koundinya 9-14-2004 at http://www.experts-exchange.com/M_372322.html

}
}
0
Question by:akaryu98

LVL 16

Accepted Solution

Hi,

Does it mean that you want to not "hard coded" the value in
/*---------------
double interest = .0575;  //Interest rate in decimal format
double amount = 200000;  // the principle amount borrowed
double payments = 360;     //Term of loan in months, basically the unmber of payments made over 30 years
-----------*/

Do you want to be in console (command prompt) or do you want to have a window-based (SWING)?

if you want to be in console, look at the URL below.
http://www.experts-exchange.com/Programming/Programming_Languages/Q_21395141.html

Regards
Dave
0

Expert Comment

I CANNOT RUN THIS PROGRAM SUCCESSFULLY. I RECEIVE AN INVALID FLAG WITHIN THE PROGRAM NAME I SUPPOSE
0

## Featured Post

### Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…