Mortgage Calculator GUI

Posted 09 October 2011 - 05:03 PM

Getting stuck on a particular part. I have the following rubric:

Write the program in Java (with a graphical user interface) so that it will allow the user to select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment or by input of the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%

In either case, display the mortgage payment amount and then, list the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection, or quit. Insert comments in the program to document the program.

I have the following code which works for the menu of terms and interest rate selections (- 7 year at 5.35%
- 15 year at 5.5 % - 30 year at 5.75%). However, I can't figure out how to implement another GUI option which would allow them to "select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment". Please help me understand how to augment this GUI to offer the other options, I'm really lost.

Replies To: Mortgage Calculator GUI

Re: Mortgage Calculator GUI

Posted 09 October 2011 - 11:28 PM

You can use a radio button group. That way the user can select which radio button choice (and only one choice) they would like. Then when it comes to calculating the mortgage, you read the radio buttons to see which is selected and create the appropriate formula.

// Create a radio button
JRadioButton byInputOfMortgage = new JRadioButton("Input of Mortgage");
// Create a group of radio buttons
ButtonGroup buttonGroup = new ButtonGroup( );
// Add button to group
buttonGroup.Add(byInputofMortgage);
// In some action event (like a button click)
if (byInputOfMortgage.isSelected()) {
// Do formula code here based on input of mortgage
}

So the first three lines above show you how to create a radio button and add it to a group. The last if statement would show you how to check if the radio button was selected. If it is selected, you then create the appropriate formula.