If this continues, you may have issues with the moderating staff. Thanks
original post:
____________________________________________________________
I am doing this calculator I have added and deleted and still get 11 errors can someone look at this and please help.
import java.text.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
public class Main {
/**
* @param args the command line arguments
*/
public class MortgageCalculator5 {
}
public static void main(String[] args) {
JFrame window = new MortCalculGUI();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
}
class MortCalcu5GUI extends JFrame implements ActionListener {
// Declare GUI function variables
protected JButton bCalc7, bCalc15, bCalc30, bClear, bExit;
protected JLabel labelPayment, labelLoanAmount, labelTitle, labelInstructions, labelAmortTable;
protected JTextField feildPayment, fieldLoanAmount;
protected JTextArea areaAmortTable;
//Declare variables and loan array and initialize with values
double InterestPaid, PrinciplePaid, Balance, monthlyPay, loanAmount;
int[] loanTerm = {7, 15, 30}; //loan term for 7 years, 15 years, and 30 years
double[] intRate = {5.35, 5.50, 5.75};//interest rates for 7 years, 15 years, and 30 years
double loanAmt = loanAmount;
public void actionPerformed (ActionEvent e) {
//Perform actions based upon which button is pressed (provides looping function)
if ("Calculate7".equals(e.getActionCommand())) {
DecimalFormat decimalPlaces = new DecimalFormat ("0.00");
NumberFormat currency = NumberFormat.getCurrencyInstance();
double paymentAmount = CalculatePayment7();
fieldPayment.setText ("" + (currency.format(paymentAmount)));
areaAmortTable.append("Payment # \t Remaining Balance \t Interest Pain\n");
loanAmt = Double.parseDouble (fieldLoanAmount.getText());
for (int x = 1; x<=(loanTerm[0]*12); x++)//Loop through all monthly payments for each loan
{
Balance = loanAmt;//Set Balance to Loan Amount
//Calculations on monthly payment
InterestPaid = (((intRate[0]/100.0)/12.0)*Balance);//Monthly Interest paid
PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
loanAmt = (Balance-PrinciplePaid);//loan balance after payment
areaAmortTable.append (x + "\t" + currency.format (loanAmt) + " \t\t" + currency.format(InterestPaid) +"n");
}
if (Balance <= 0)//ending statement, balance at $0.00
{
areaAmortTable.append ("\tRemaining balance = $0.00");
//paymentNumber = 0;
//InterestedPaid = 0.0;
}
}
else if ("Calculate15".equals(e.getActionCommand()))
{
DecimalFormat decimalPlaces = new DecimalFormat ("0.00");
NumberFormat currency = NumberFormat.getCurrencyInstance();
double paymentAmount = CalculatePayment15();
fieldPayment.setText ("" + (currency.format(paymentAmount)));
areaAmortTable.append ("Payment # \t Remaining Balance \t Interest Paid\n");
loanAmt = Double.parseDouble(fieldLoanAmount.getText());
for (int x = 1; x<=(loanTerm[1]*12); x++)//Loop through all monthly payment for each loan
{
Balance = loanAmt;
//Calculation on monthly payment
InterestPaid = ((intRate[1]/100/12)*Balance);//Monthly Interest paid
PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
loanAmt = ((Balance-PrinciplePaid));//loan balance after payment
areaAmortTable.append (x + '\t' + currency.format (loanAmt) + "\t\t" + currency.format (InterestPaid)+ '\n');
}
if (loanAmt <= 0)//ending statement, blance at $0.00
{
areaAmortTable.append ("\tRemaining balance = $0.00");
//paymentNumber =0;
//InterestPaid = 0.0;
}
}
else if ("calculate30".equals(e.getActionCommand()))
{
DecimalFormat decimalPlaces = new DecimalFormat("0.00");
NumberFormat currency = NumberFormat.getCurrencyInstance();
double paymentAmount = CalculatePayment30();
fieldPayment.setText ("" + (currency.format (paymentAmount)));
areaAmortTable.append ("payment # \t Remaining Balance \t Interest Paid\n");
loanAmt = Double.parseDouble (fieldLoanAmount.getText());
for (int x = 1; x<=(loanTerm[2]*12); x++)//Loop through all monthly payments for each loan
{
Balance = loanAmt;
//Calulations on monthly payments
InterestPaid = ((intRate[2]/100/12)*Balance);//Monthly Interest Paid
PrinciplePaid = (paymentAmount-InterestPaid);//Applied toward principle
areaAmortTable.append (x + "\t" + currency.format(loanAmt) + "\t\t" + currency.format(InterestPaid)+"\n");
}
if (loanAmt <= 0)//ending statement, balance at $0.00
{
areaAmortTable.append ("\tRemaining balance = $0.00");
//paymentNumber = 0;
//InterstPaid =0.0;
}
}
else if ("Clear".equals(e.getActionCommand()))
{
ClearFields();
}
else
{
//end and close application
System.exit(0);
}
}
public double CalculatePayment7 ()
{
//Check for numeric input
try
{
//Perform payment calculations if input is valid
fieldPayment.setText ("");
double Payment = (loanAmount()* (intRate[0]/100/12)) / (1- Math.pow(1/(1 + (intRate[0]/100/12)), loanTerm[0]*12));
return Payment;
}
catch (NumberFormatException event)
{
//Display error message if input is invalid
JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease enter only numeric values!!","ERROR",
JOptionPane.ERROR_MESSAGE);
return 0;
}
}
public double CalculationPayment15()
{
//Check for valid input
try
{
//Perform payment calculations if input is valid
fieldpayment.setText ("");
double Payment = (loanAmount( )* (intRate[1]/100/12)) / (1 - Math.pow(1/(1 +(intRate[1]/100/12)),loanTerm[1]*12));
return Payment;
}
catch (NumberFormatException event)
{
//Display erroe message if input is invalid
JOptionPane.showMessageDialog(null, "Invalid entry!\nPlease enter only numeric values!!",
"ERROR", JOptionPane.ERROR_MESSAGE);
return 0;
}
}
public double CalculatePayment30()
{
//Check for vilid numeric input
try
{
//Perform payment calculation if input in valid
fieldPayment.setText ("");
double Payment = (loanAmount()* (intRate[2]/100/12))/(1 - Math.pow (1/(1 + (intRate[2]/100/12)), loanTerm[2]*12));
return Payment;
}
catch (NumberFormatException event)
{
//Display error message if input is invalid
JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease enter only numeric values!!",
"ERROR", JOptionPane.ERROR_MESSAGE);
return 0;
}
}
public void ClearFields()
{
//Set all text to blank
fieldPayment.setText ("");
fieldLoanAmount.setText ("");
areaAmortTable.setText ("");
}
public MortCalcu5GUI ();
{
//Set up and initialize buttons for GUI
bCalc7 = new JButton ("7 Year, 5.32%");
bCalc7.setActionCommand ("Calculate7");
bCalc15 = new JButton ("15 Years, 5.50%");
bCalc15.setActionCommand ("Calculate15");
bCalc30 = new JButton ("30 Years, 5.75%");
bCalc30.setActionCommand ("Calculate30");
bClear = new JButton ("Clear All Fields");
bClear.setActionCommand ("Clear");
bExit = new JButton ("Exit Program");
bExit.setActionCommand ("Exit");
//Set up labels and field sizes for GUI
labelTitle = new JLabel ("McBride Mortgage Calculator V3.5");
labelInstructions = new JLabel ("Enter the amount of the Loan and then choose the term/rate of the loan.");
labelPayment = new JLabel ("Monthly Payment:");
labelLoanAmount = new JLabel ("Amount of Loan:");
fieldPayment = new JTextField ("", 12);
fieldLoanAmount = new JTextField ("", 10);
labelAmortTable = new JLabel ("Amortization Table");
areaAmortTable = new JTextArea (10, 300);
JScrollPane scrollPane = new JScrollPane (areaAmortTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//Set up listerners for each button
bCalc7.addActionListener (this);
bCalc15.addActionListener (this);
bCalc30.addActionListener (this);
bClear.addActionListener (this);
bExit.addActionListener (this);
}
public double loanAmount ()
{
double loanAmount = Double.parseDouble (fieldLoanAmount.getText());
return loanAmount;
}
}
This post has been edited by Dogstopper: 24 March 2010 - 01:45 PM

New Topic/Question
Reply



MultiQuote







|