Here is what I am attempting on doing: Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage. Allow the user to loop back and enter new data or quit. Please insert comments in the program to document the program.
package mortgagecalc4;
import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.text.;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
public class Mortgagecalc4{
private static final int FRAME_WIDTH = 150;
private static final int FRAME_HEIGHT = 120;
// Keeps track of the current operation (subtract, add, etc)
private static final int Decline_Calculation = 0;
private static final int ADDITION = 1;
public static int Calculation = Decline_Calculation;
public static JTextField textFieldDisplay;
public static double Set1 = 0; // holds the value before the operation
public static void main(String[] args) {
// Set up the user interface
JFrame frame = new JFrame();
JPanel buttonSet = new JPanel();
frame.add(buttonSet);
// create two buttons, plus and equal and a text box for answers
textFieldDisplay = new JTextField(10);
buttonSet.add(textFieldDisplay);
JButton buttoncalculate = new JButton(" MC ");
buttonSet.add(calculate);
JButton buttonpercent = new JButton(" % ");
buttonSet.add(percent);
JButton buttonequation = new JButton(" E ");
buttonSet.add(equation);
JButton buttonaddition = new JButton(" + ");
buttonSet.add(addition);
JButton buttonTotal = new JButton(" Total ");
buttonSet.add(total);
JButton.buttonsquareroot = new JButton(" ^ ");
buttonSet.add(squareroot);
JButton.buttondivide = new JButton(" / ");
buttonSet.add(divide);
JButton.buttonsubtract = new JButton(" - ");
buttonSet.add(subtract);
JButton.buttonequals = new JButton(" = ");
buttonSet.add(equals);
JButton.buttonstage = new JButton(" STG ");
buttonSet.add(stage);
JButton.buttonclear = new JButton(" CE ");
buttonSet.add(clear);
JButton.buttoninterest = new JButton(" interest ");
buttonSet.add(interest);
JButton.buttonaverage = new JButton(" average ");
buttonSet.add(average);
JButton.buttonbalance = new JButton(" balance ");
buttonSet.add(balance);
JButton.buttonsave = new JButton(" save ");
buttonSet.add(save);
// frame size the the calculator
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Mortgage Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// called when the equal sign '=' is pressed
class EqualSignListener implements ActionListener {
public void actionPerformed(ActionEvent event)
{
double Set2 = Double.parseDouble(textFieldDisplay.getText());
if (Calculation == ADDITION) {
// plus sign pressed before the equal sign
Set2 += Set1;
}
// Convert from a answer to a string
Double answer = new Double(Set2);
textFieldDisplay.setText( answer.toString() );
// Reset the operation to show no current operation
Calculation = Decline_Calculation;
}
}
// called when a plus sign '+' is pressed
class PlusSignListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent event)
{
Set1 = Double.parseDouble(textFieldDisplay.getText());
Calculation = ADDITION;
}
}
// Add the methods that will be called when these buttons are pressed
ActionListener AdditionSignListener = new AdditionSignListener();
buttonaddition.addActionListener(AdditionSignListener);
ActionListener equalSignListener = new EqualSignListener();
buttonequals.addActionListener(equalSignListener);
{
public static void(String[] args) throws IOException
{
//Declare variable for loan amount
double LoanAmt = 200000;
double Principle1, Principle2, Principle3;
double Payments1, Payments2, Payments3;// creates variable for three different payment amounts
double Monthlyinterest1, Monthlyinterest2, Monthlyinterest3; //creates variables for three differene interest amounts
double Monthlyprinciple1, Monthlyprinciple2, Monthlyprinciple3; //creates variables for three different principal paymentamounts
Principle1 = LoanAmt;
Principle2 = LoanAmt;
Principle3 = LoanAmt;
Monthlyprinciple1 = 0;
Monthlyprinciple2 = 0;
Monthlyprinciple3 = 0;
Monthlyinterest1 = 0;
Monthlyinterest2 = 0;
Monthlyinterest3 = 0;
int Count = 1;
//create loan term array
double [] Term = {84, 180, 360};
//create interest rate array
double [] Rate = {.0535, .055, .0575};
//calculations for each payment amount
Payments1 = (LoanAmt * Rate[0]/12) / (1-Math.pow(1+Rate[0]/12,-Term[0]));
Payments2 = (LoanAmt * Rate[1]/12) / (1-Math.pow(1+Rate[1]/12,-Term[1]));
Payments3 = (LoanAmt * Rate[2]/12) / (1-Math.pow(1+Rate[2]/12,-Term[2]));
//output
System.out.println("\t\tMonthly Payment Schedule");
System.out.println();
System.out.println("\t\tLoan Amount: $200,000.00");
System.out.println("\t\tTerm: 7 Years");
System.out.println("\t\tInterest Rate 5.35%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", Payments1);
System.out.println();
System.out.println("\t\tTerm: 15 Years");
System.out.println("\t\tInterest Rate 5.5%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", Payments2);
System.out.println();
System.out.println("\t\tTerm: 30 Years");
System.out.println("\t\tInterest Rate 5.75%");
System.out.printf("\t\tThe monthly payment amount is $%.2f", Payments3);
System.out.println();
if (Principle1 <= 0)
{
//monthly calculations for first payment amount
Monthlyinterest1 = (Principle1 * Rate[0]) / 365 * 30;
Monthlyprinciple1 = (Payments1 - Monthlyinterest1);
Principle1 = (Principle1 - Monthlyprinciple1);
if (Principle1 <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", Monthlyinterest1);
System.out.println("");
System.out.printf("Principal payment: $%.2f", Monthlyprinciple1);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", Principle1);
System.out.println("");
Count++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
}
}
else if (Principle2 <= 0)
{
//monthly calculations for first payment amount
Monthlyinterest2 = (Principle2 * Rate[0]) / 365 * 30;
Monthlyprinciple2 = (Payments2 - Monthlyinterest2);
Principle2 = (Principle2 - Monthlyprinciple2);
if (Principle1 <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", Monthlyinterest2);
System.out.println("");
System.out.printf("Principal payment: $%.2f", Monthlyprinciple2);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", Principle2);
System.out.println("");
Count++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
}
}
else if (Principle3 <= 0)
{
//monthly calculations for first payment amount
Monthlyinterest3 = (Principle3 * Rate[0]) / 365 * 30;
Monthlyprinciple3 = (Payments3 - Monthlyinterest3);
Principle3 = (Principle3 - Monthlyprinciple3);
if (Principle2 <= 0)
{
//outputs
System.out.printf("Interest payment: $%.2f", Monthlyinterest3);
System.out.println("");
System.out.printf("Principal payment: $%.2f", Monthlyprinciple3);
System.out.println("");
System.out.printf("New Principal Balance: $%.2f", Principle3);
System.out.println("");
Count++;
}
else
{
System.out.printf("The principal balance is $0.00");
System.out.printf("");
}
}
System.exit(0);
}
}
Here is the errors I am getting.
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:3: <identifier> expected
import java.awt.;
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:4: <identifier> expected
import java.awt.event.;
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:5: <identifier> expected
import javax.swing.;
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:6: <identifier> expected
import javax.swing.text.;
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: illegal start of expression
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: illegal start of expression
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: ';' expected
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: ')' expected
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: not a statement
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: ';' expected
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: not a statement
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:132: ';' expected
public static void(String[] args) throws IOException
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\src\mortgagecalc4\Mortgagecalc4.java:264: reached end of file while parsing
}
^
13 errors
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\Falloncade\Documents\NetBeansProjects\mortgagecalc4\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 2 seconds)
Once again thank you so much for your help. I can't thank you enough. This is hard for me to learn, but I am hoping with your help and guidance I will pick it up.

New Topic/Question
Reply



MultiQuote







|