Solved

Trouble reading a file with term and rate.

Posted on 2006-06-21
13
218 Views
Last Modified: 2010-04-16
I am having several issues with my mortgage calculator. I am trying to read a file with the following values. I am not sure the file actually will read because I am getting compiler errors.
Any assistance would be apreciated.
Thanks,
Jon

7,5.35
15,5.5
30,5.75

the fiirst value in each row is the term, the second is the yearly interest rate. I added a file reader and now get the following errors.

C:\java\java2\Week 5 program\Mortgage.java:378: operator * cannot be applied to java.lang.String,int
            int monthCount = (TermArrayNew[i] * 12);
                                              ^
C:\java\java2\Week 5 program\Mortgage.java:384: operator / cannot be applied to java.lang.String,int
            interestRateMonthly = (YearlyInterestArrayNew[i] / 12) / 100;
                                                             ^
C:\java\java2\Week 5 program\Mortgage.java:449: operator < cannot be applied to int,java.lang.String
            for (int a = 0; a < TermArrayNew[i]; a = a + 1)
                              ^
Note: C:\java\java2\Week 5 program\Mortgage.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

Tool completed with exit code 1



My code is below

//week3 Jan Schab


/* Mortgage Monyhly Payment Calculator with graphical user interface
Programmer:  J.Schab
Date:        June 10,2006
Filename:    Mortgage.java
Purpose:     This project accepts the mortgage and allows  the user to select one of 3
pre-determined loans.The program then calculates the monthly mortgage payment and displays
it in currency format. The program then allows the user to display the payment number,
the monthly principle paid, the monthly interest paid, and the current loan balance
through the push of an addition button; There is a quit button to exit the application,
and a clear button to clear user entered fields as well as the amortization table.in
order to calculate a new mortgage. The program will also clear the payment field should
the user press any key while positioned in the input textfield for amount. The payment and
amortizatin table will also be cleared if the user changes the radio buttons.


 */



import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JScrollPane.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.NumberFormat;
import java.util.Locale;
import java.text.*;
import java.text.DecimalFormat;
import java.io.FileReader;
import java.io.BufferedReader;
import java.text.NumberFormat;
import java.util.ArrayList;




class Mortgage extends JFrame implements ActionListener
{


    //Program variables





    int payment = 0; // payment counter
    int i = 0; // used as index
    // initialize variable for monthly interest rate
    double monthlyInterest = 0.00;
    // variable to store principle
    double principle = 0.00;
    // initialize mothly principle paid field
    double monthlyPrinciplePaid = 0.00;
    // Variable to hold maonthly interest
    double interestRateMonthly = 0.00;
    // variable to store calculated monthly payment
    double monthlyPayment;
    // variable to store descending balance
    int amount = 0;
    String YearlyInterestArrayNew[] = null;

      String TermArrayNew[] = null;

      String InputFile = ".\\TermRate.dat";




    private JLabel headerJLabel;

    Border rowborder = new EmptyBorder(3, 10, 3, 10);
    // Format output
    DecimalFormat currency = new DecimalFormat("$0.00");


    // JLabel and JTextField for the mortgage amount
    private JLabel amountJLabel;
    private JTextField amountJTextField;

    // JLabel for monthly mortgage payment
    private JLabel monthpayJLabel;

    // JTextArea for displaying payment
    private JTextArea outputJTextArea;


    // JButton to initiate calculations
    private JButton calculateJButton;

    // JButton to display amortization table
    private JButton displayJButton;

    // JButton to clear entries
    private JButton clearJButton;

    // JButton to quit
    private JButton quitJButton;


    // Create radio panel
    JPanel radioPanel = new JPanel();
    JRadioButton aButton = new JRadioButton("7 Years at 5.35%", true);
    JRadioButton bButton = new JRadioButton("15 Years at 5.50%", false);
    JRadioButton cButton = new JRadioButton("30 Years at 5.75%", false);


    // create scroll box with display area
    JTextArea displayArea = new JTextArea(10, 45);
    JScrollPane scroll = new JScrollPane(displayArea);





    // no-argument constructor
    public Mortgage()



    {
        createUserInterface();
    }

    // create and position the GUI components; register event handlers
    private void createUserInterface()
    {
        // get content pane for attaching GUI components
        Container contentPane = getContentPane();

        setTitle("Mortgage Calculator"); // set title bar text


        // set northLabel using borderlayout
        headerJLabel = new JLabel();
        headerJLabel.setBounds(10, 1, 300, 46); // set size and position
        headerJLabel.setText("Enter a mortgage amount and select a loan");
        contentPane.add(headerJLabel);

        // enable specific positioning of GUI components
        contentPane.setLayout(null);

        // set up amountJLabel
        amountJLabel = new JLabel();
        amountJLabel.setBounds(76, 36, 104, 26); // set size and position
        amountJLabel.setText("Mortgage amount:");
        contentPane.add(amountJLabel);

        // set up amountJTextField
        amountJTextField = new JTextField();
        amountJTextField.setBounds(200, 36, 56, 26); // set size and position
        amountJTextField.setHorizontalAlignment(JTextField.RIGHT);
        contentPane.add(amountJTextField);
        amountJTextField.addKeyListener(

        new KeyAdapter() // anonymous inner class
        {
            // event handler for key pressed in amountJTextField
            public void keyPressed(KeyEvent event)
            {
                amountJTextFieldkeyPressed(event);
            }

        } // end anonymous inner class

        ); // end call to addKeyListener



        // create radio buttons and panel
        ButtonGroup bgroup = new ButtonGroup();
        // add listeners for radio buttons
        aButton.addActionListener(this);
        bButton.addActionListener(this);
        cButton.addActionListener(this);
        bgroup.add(aButton);
        bgroup.add(bButton);
        bgroup.add(cButton);
        radioPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));
        radioPanel.add(aButton);
        radioPanel.add(bButton);
        radioPanel.add(cButton);
        contentPane.add(radioPanel);
        radioPanel.setBorder(rowborder);
        radioPanel.setBounds(90, 56, 195, 95); // set size and position



        // set up calculateJButton
        calculateJButton = new JButton();
        calculateJButton.setBounds(26, 155, 90, 26); // set size and position
        calculateJButton.setText("Calculate");
        contentPane.add(calculateJButton);
        calculateJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when calculateJButton is pressed
            public void actionPerformed(ActionEvent event)
            {

                calculateJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up displayJButton
        displayJButton = new JButton();
        displayJButton.setBounds(26, 216, 200, 26); // set size and position
        displayJButton.setText("Display Amortization Table");
        contentPane.add(displayJButton);
        displayJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when clearJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                displayJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener




        // set up clearJButton
        clearJButton = new JButton();
        clearJButton.setBounds(70, 380, 90, 26); // set size and position
        clearJButton.setText("Clear");
        contentPane.add(clearJButton);
        clearJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when clearJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                clearJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up quitJButton
        quitJButton = new JButton();
        quitJButton.setBounds(230, 380, 90, 26); // set size and position
        quitJButton.setText("Quit");
        contentPane.add(quitJButton);
        quitJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when quitJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                quitJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up outputJTextArea
        outputJTextArea = new JTextArea();
        contentPane.add(outputJTextArea);
        outputJTextArea.setBounds(300, 155, 56, 26); // set size and position
        outputJTextArea.setEditable(false);

        //set up monthpayJLabel
        monthpayJLabel = new JLabel();
        monthpayJLabel.setBounds(176, 155, 156, 26); // set size and position
        monthpayJLabel.setText("Monthly Payment:");
        contentPane.add(monthpayJLabel);

        scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        contentPane.add(scroll);
        scroll.setBounds(20, 240, 369, 130); // set size and position
        setVisible(true);
        displayArea.setEditable(false);

FileReader InputFile;
          try {
               InputFile = new FileReader("TermRate.dat");
               BufferedReader data = new BufferedReader(InputFile);
               String aline = null;
               java.util.ArrayList array = new java.util.ArrayList();
               while ((aline = data.readLine()) != null)
                    array.add(aline);
               YearlyInterestArrayNew = new String[array.size()];
               TermArrayNew = new String[array.size()];
               for (int i = 0; i < array.size(); i++) {
                    String[] line = ((String) array.get(i)).split(",");
                    YearlyInterestArrayNew[i] = line[0].trim();
                    TermArrayNew[i] = line[1].trim();
               }

               InputFile.close();
          } catch (Exception e1) {
               e1.printStackTrace();
          }

          //MyComboBox();
     //}


            //double Term = Double.parseDouble((String)TermArrayNew.get(i));
            //double Interest = Double.parseDouble((String)YearlyInterestArrayNew.get(i));






    } // end method createUserInterface

    // called when user presses key in amountJTextField
    private void amountJTextFieldkeyPressed(KeyEvent event)
    {
        outputJTextArea.setText(""); // clear outputJTextArea
        displayArea.setText(""); // clear display
        payment = 0; // reset payment counter
    }

    // method called when user clicks calculateJButton
    private void calculateJButtonActionPerformed(ActionEvent event)
    {
        try
        {
            // check which radio buttonis selected and set index
            if (aButton.isSelected())
            {
                i = 0;
            }


            if (bButton.isSelected())
            {
                i = 1;
            }


            if (cButton.isSelected())
            {
                i = 2;
            }





            //define display area titles
            String titles = "Month \t Principal\t Interest\tBalance\n";
            //put titles in display area
            displayArea.setText(titles);
            // initialize loan balance field
            double loanbalance = 0.00;

            // initialize payment counter

            // clear outputJTextArea
            outputJTextArea.setText("");
            // clear display area
            displayArea.setText("");
            // Calculate months from years
            int monthCount = (TermArrayNew[i] * 12);
            // get mortgage amount
            amount = Integer.parseInt(amountJTextField.getText());
            //create variable to store decreasing principle
            principle = amount;
            // Calculate monthly interest
            interestRateMonthly = (YearlyInterestArrayNew[i] / 12) / 100;


            // Calculate monthly payment
            monthlyPayment = (amount * interestRateMonthly) / (1-Math.pow(1
                +interestRateMonthly,  - monthCount));




            // Output payment amount
            outputJTextArea.setText(currency.format(monthlyPayment));



        }

        catch (NumberFormatException ex){}
    }





    // method called when user clicks clearJButton
    private void clearJButtonActionPerformed(ActionEvent event)
    {
        try
        {

            monthlyPrinciplePaid = 0.00; // initialize principle paid field
            outputJTextArea.setText(""); // clear outputJTextArea
            amountJTextField.setText(""); // clear amountJTextField
            displayArea.setText(""); // clear display area
            payment = 0; // reset payment counter




        }
        catch (NumberFormatException ex){}
    }


    // method called when user clicks displayJButton
    private void displayJButtonActionPerformed(ActionEvent event)
    {
        try
        {

            // reset values in case user presses display more than once
            principle = Integer.parseInt(amountJTextField.getText());
            monthlyPrinciplePaid = 0.00;
            displayArea.setText(""); // clear display
            payment = 0;
            monthlyPrinciplePaid = 0.00;

            //define display area titles
            String titles = "Month \t Principal\t Interest\tBalance\n";
            //put titles in display area
            displayArea.setText(titles);
            // initialize loan balance field


            // loop for creating amortization table
            for (int a = 0; a < TermArrayNew[i]; a = a + 1)
            {
                //increment payment counter
                payment++;
                // calculate monthly interest
                monthlyInterest = principle * interestRateMonthly;
                // calculate monthly principle
                monthlyPrinciplePaid = monthlyPayment - monthlyInterest; //
                //save declining balance
                principle = principle - monthlyPrinciplePaid;


                // display amortization table
                displayArea.append(payment + "\t" + currency.format
                    (monthlyPrinciplePaid) + "\t" + currency.format
                    (monthlyInterest) + "\t" + currency.format(Math.abs
                    (principle)) + "\n");
                displayArea.setCaretPosition(0);


            }
        }

        catch (NumberFormatException ex){}
    }




    // method called when user clicks quitJButton
    private void quitJButtonActionPerformed(ActionEvent event)
    {
        try
        {
            System.exit(0);

        }
        catch (NumberFormatException ex){}
    }

    // method called when user clicks on a radio button
    public void actionPerformed(ActionEvent e)
    {
        displayArea.setText(""); // clear display
        outputJTextArea.setText(""); // clear outputJTextArea



    }
    // main method
    public static void main(String[]args)
    {
        Mortgage application = new Mortgage();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.setSize(400, 450);
        application.setVisible(true);
    } // end method main

} // end class Mortgage
0
Comment
Question by:ghost8067
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
Comment Utility
>>TermArrayNew[i]

You  need to do

Integer.parseInt(TermArrayNew[i])

and similar
0
 

Author Comment

by:ghost8067
Comment Utility
I apoligize, but I seem to be either doing it wron or putting it in the wrong place.
The new error is

C:\java\java2\Week 5 program\Mortgage.java:385: operator * cannot be applied to java.lang.String,int
            int monthCount = Integer.parseInt(TermArrayNew[i] * 12);

Code below.
Jon

//week3 Jan Schab


/* Mortgage Monyhly Payment Calculator with graphical user interface
Programmer:  J.Schab
Date:        June 10,2006
Filename:    Mortgage.java
Purpose:     This project accepts the mortgage and allows  the user to select one of 3
pre-determined loans.The program then calculates the monthly mortgage payment and displays
it in currency format. The program then allows the user to display the payment number,
the monthly principle paid, the monthly interest paid, and the current loan balance
through the push of an addition button; There is a quit button to exit the application,
and a clear button to clear user entered fields as well as the amortization table.in
order to calculate a new mortgage. The program will also clear the payment field should
the user press any key while positioned in the input textfield for amount. The payment and
amortizatin table will also be cleared if the user changes the radio buttons.


 */



import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JScrollPane.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.NumberFormat;
import java.util.Locale;
import java.text.*;
import java.text.DecimalFormat;
import java.io.FileReader;
import java.io.BufferedReader;
import java.text.NumberFormat;
import java.util.ArrayList;




class Mortgage extends JFrame implements ActionListener
{


    //Program variables





    int payment = 0; // payment counter
    int i = 0; // used as index
    // initialize variable for monthly interest rate
    double monthlyInterest = 0.00;
    // variable to store principle
    double principle = 0.00;
    // initialize mothly principle paid field
    double monthlyPrinciplePaid = 0.00;
    // Variable to hold maonthly interest
    double interestRateMonthly = 0.00;
    // variable to store calculated monthly payment
    double monthlyPayment;
    // variable to store descending balance
    int amount = 0;
    String YearlyInterestArrayNew[] = null;

      String TermArrayNew[] = null;

      String InputFile = ".\\TermRate.dat";




    private JLabel headerJLabel;

    Border rowborder = new EmptyBorder(3, 10, 3, 10);
    // Format output
    DecimalFormat currency = new DecimalFormat("$0.00");


    // JLabel and JTextField for the mortgage amount
    private JLabel amountJLabel;
    private JTextField amountJTextField;

    // JLabel for monthly mortgage payment
    private JLabel monthpayJLabel;

    // JTextArea for displaying payment
    private JTextArea outputJTextArea;


    // JButton to initiate calculations
    private JButton calculateJButton;

    // JButton to display amortization table
    private JButton displayJButton;

    // JButton to clear entries
    private JButton clearJButton;

    // JButton to quit
    private JButton quitJButton;


    // Create radio panel
    JPanel radioPanel = new JPanel();
    JRadioButton aButton = new JRadioButton("7 Years at 5.35%", true);
    JRadioButton bButton = new JRadioButton("15 Years at 5.50%", false);
    JRadioButton cButton = new JRadioButton("30 Years at 5.75%", false);


    // create scroll box with display area
    JTextArea displayArea = new JTextArea(10, 45);
    JScrollPane scroll = new JScrollPane(displayArea);





    // no-argument constructor
    public Mortgage()



    {
        createUserInterface();
    }

    // create and position the GUI components; register event handlers
    private void createUserInterface()
    {
        // get content pane for attaching GUI components
        Container contentPane = getContentPane();

        setTitle("Mortgage Calculator"); // set title bar text


        // set northLabel using borderlayout
        headerJLabel = new JLabel();
        headerJLabel.setBounds(10, 1, 300, 46); // set size and position
        headerJLabel.setText("Enter a mortgage amount and select a loan");
        contentPane.add(headerJLabel);

        // enable specific positioning of GUI components
        contentPane.setLayout(null);

        // set up amountJLabel
        amountJLabel = new JLabel();
        amountJLabel.setBounds(76, 36, 104, 26); // set size and position
        amountJLabel.setText("Mortgage amount:");
        contentPane.add(amountJLabel);

        // set up amountJTextField
        amountJTextField = new JTextField();
        amountJTextField.setBounds(200, 36, 56, 26); // set size and position
        amountJTextField.setHorizontalAlignment(JTextField.RIGHT);
        contentPane.add(amountJTextField);
        amountJTextField.addKeyListener(

        new KeyAdapter() // anonymous inner class
        {
            // event handler for key pressed in amountJTextField
            public void keyPressed(KeyEvent event)
            {
                amountJTextFieldkeyPressed(event);
            }

        } // end anonymous inner class

        ); // end call to addKeyListener



        // create radio buttons and panel
        ButtonGroup bgroup = new ButtonGroup();
        // add listeners for radio buttons
        aButton.addActionListener(this);
        bButton.addActionListener(this);
        cButton.addActionListener(this);
        bgroup.add(aButton);
        bgroup.add(bButton);
        bgroup.add(cButton);
        radioPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));
        radioPanel.add(aButton);
        radioPanel.add(bButton);
        radioPanel.add(cButton);
        contentPane.add(radioPanel);
        radioPanel.setBorder(rowborder);
        radioPanel.setBounds(90, 56, 195, 95); // set size and position



        // set up calculateJButton
        calculateJButton = new JButton();
        calculateJButton.setBounds(26, 155, 90, 26); // set size and position
        calculateJButton.setText("Calculate");
        contentPane.add(calculateJButton);
        calculateJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when calculateJButton is pressed
            public void actionPerformed(ActionEvent event)
            {

                calculateJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up displayJButton
        displayJButton = new JButton();
        displayJButton.setBounds(26, 216, 200, 26); // set size and position
        displayJButton.setText("Display Amortization Table");
        contentPane.add(displayJButton);
        displayJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when clearJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                displayJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener




        // set up clearJButton
        clearJButton = new JButton();
        clearJButton.setBounds(70, 380, 90, 26); // set size and position
        clearJButton.setText("Clear");
        contentPane.add(clearJButton);
        clearJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when clearJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                clearJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up quitJButton
        quitJButton = new JButton();
        quitJButton.setBounds(230, 380, 90, 26); // set size and position
        quitJButton.setText("Quit");
        contentPane.add(quitJButton);
        quitJButton.addActionListener(

        new ActionListener() // anonymous inner class
        {
            // event handler called when quitJButton is pressed
            public void actionPerformed(ActionEvent event)
            {
                quitJButtonActionPerformed(event);
            }

        } // end anonymous inner class

        ); // end call to addActionListener


        // set up outputJTextArea
        outputJTextArea = new JTextArea();
        contentPane.add(outputJTextArea);
        outputJTextArea.setBounds(300, 155, 56, 26); // set size and position
        outputJTextArea.setEditable(false);

        //set up monthpayJLabel
        monthpayJLabel = new JLabel();
        monthpayJLabel.setBounds(176, 155, 156, 26); // set size and position
        monthpayJLabel.setText("Monthly Payment:");
        contentPane.add(monthpayJLabel);

        scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        contentPane.add(scroll);
        scroll.setBounds(20, 240, 369, 130); // set size and position
        setVisible(true);
        displayArea.setEditable(false);

FileReader InputFile;
          try {
               InputFile = new FileReader("TermRate.dat");
               BufferedReader data = new BufferedReader(InputFile);
               String aline = null;
               java.util.ArrayList array = new java.util.ArrayList();
               while ((aline = data.readLine()) != null)
                    array.add(aline);
               YearlyInterestArrayNew = new String[array.size()];
               TermArrayNew = new String[array.size()];
               for (int i = 0; i < array.size(); i++) {
                    String[] line = ((String) array.get(i)).split(",");
                    YearlyInterestArrayNew[i] = line[0].trim();
                    TermArrayNew[i] = line[1].trim();


               }

               InputFile.close();
          } catch (Exception e1) {
               e1.printStackTrace();
          }

          //MyComboBox();
     //}


            //double Term = Double.parseDouble((String)TermArrayNew.get(i));
            //double Interest = Double.parseDouble((String)YearlyInterestArrayNew.get(i));






    } // end method createUserInterface

    // called when user presses key in amountJTextField
    private void amountJTextFieldkeyPressed(KeyEvent event)
    {
        outputJTextArea.setText(""); // clear outputJTextArea
        displayArea.setText(""); // clear display
        payment = 0; // reset payment counter
    }

    // method called when user clicks calculateJButton
    private void calculateJButtonActionPerformed(ActionEvent event)
    {
        try
        {
            // check which radio buttonis selected and set index
            if (aButton.isSelected())
            {
                i = 0;
            }


            if (bButton.isSelected())
            {
                i = 1;
            }


            if (cButton.isSelected())
            {
                i = 2;
            }





            //define display area titles
            String titles = "Month \t Principal\t Interest\tBalance\n";
            //put titles in display area
            displayArea.setText(titles);
            // initialize loan balance field
            double loanbalance = 0.00;

            // initialize payment counter

            // clear outputJTextArea
            outputJTextArea.setText("");
            // clear display area
            displayArea.setText("");
            // Calculate months from years
            //Integer.parseInt(TermArrayNew[i]);
                  //Integer.parseInt(YearlyInterestArrayNew[i]);



            int monthCount = Integer.parseInt(TermArrayNew[i] * 12);
            // get mortgage amount
            amount = Integer.parseInt(amountJTextField.getText());
            //create variable to store decreasing principle
            principle = amount;
            // Calculate monthly interest
            interestRateMonthly = (YearlyInterestArrayNew[i] / 12) / 100;


            // Calculate monthly payment
            monthlyPayment = (amount * interestRateMonthly) / (1-Math.pow(1
                +interestRateMonthly,  - monthCount));




            // Output payment amount
            outputJTextArea.setText(currency.format(monthlyPayment));



        }

        catch (NumberFormatException ex){}
    }





    // method called when user clicks clearJButton
    private void clearJButtonActionPerformed(ActionEvent event)
    {
        try
        {

            monthlyPrinciplePaid = 0.00; // initialize principle paid field
            outputJTextArea.setText(""); // clear outputJTextArea
            amountJTextField.setText(""); // clear amountJTextField
            displayArea.setText(""); // clear display area
            payment = 0; // reset payment counter




        }
        catch (NumberFormatException ex){}
    }


    // method called when user clicks displayJButton
    private void displayJButtonActionPerformed(ActionEvent event)
    {
        try
        {

            // reset values in case user presses display more than once
            principle = Integer.parseInt(amountJTextField.getText());
            monthlyPrinciplePaid = 0.00;
            displayArea.setText(""); // clear display
            payment = 0;
            monthlyPrinciplePaid = 0.00;


            //define display area titles
            String titles = "Month \t Principal\t Interest\tBalance\n";
            //put titles in display area
            displayArea.setText(titles);
            // initialize loan balance field


            // loop for creating amortization table
            for (int a = 0; a < TermArrayNew[i]; a = a + 1)
            {
                //increment payment counter
                payment++;
                // calculate monthly interest
                monthlyInterest = principle * interestRateMonthly;
                // calculate monthly principle
                monthlyPrinciplePaid = monthlyPayment - monthlyInterest; //
                //save declining balance
                principle = principle - monthlyPrinciplePaid;


                // display amortization table
                displayArea.append(payment + "\t" + currency.format
                    (monthlyPrinciplePaid) + "\t" + currency.format
                    (monthlyInterest) + "\t" + currency.format(Math.abs
                    (principle)) + "\n");
                displayArea.setCaretPosition(0);


            }
        }

        catch (NumberFormatException ex){}
    }




    // method called when user clicks quitJButton
    private void quitJButtonActionPerformed(ActionEvent event)
    {
        try
        {
            System.exit(0);

        }
        catch (NumberFormatException ex){}
    }

    // method called when user clicks on a radio button
    public void actionPerformed(ActionEvent e)
    {
        displayArea.setText(""); // clear display
        outputJTextArea.setText(""); // clear outputJTextArea



    }
    // main method
    public static void main(String[]args)
    {
        Mortgage application = new Mortgage();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.setSize(400, 450);
        application.setVisible(true);
    } // end method main

} // end class Mortgage

0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
try:

      int monthCount = Integer.parseInt(TermArrayNew[i]) * 12;
0
 

Author Comment

by:ghost8067
Comment Utility
It compiles now but does not give any value for the result. It also gives me the following warning. Any idea what this is?

Note: C:\java\java2\Week 5 program\Mortgage.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Tool completed successfully

I couldn't get it to work with  the calculation below.
interestRateMonthly = (YearlyInterestArrayNew[i] / 12) / 100;

I created an interim variable as a douple (double calcValue = Double.parseDouble(TermArrayNew[i]);) and then did the calculation. I am not sure if this will hurt the calculation.
interestRateMonthly = (calcValue / 12) / 100;

Your answer worked for that issue, so I am accepting it. I was also wondering if you can see if I am doing something wrong when populating the array from the file since I get no result.
Thanks,
Jon
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
ghost8067, can you tell me why you accepted answer when i'd already told you that?
0
 

Author Comment

by:ghost8067
Comment Utility
I apoligize. That was my mistake. I am a relative newbie at this, and did not notice that it was a different person that left the update.I should have looked more carefully.  I thought it was you. I now can see it was a different responder. Is there a way I can give points to you also?
I am sorry, the points should have gone to you.
Jon
 
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
OK don't worry - i'll get the question reopened.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
A split is fine with me :)
0
 

Author Comment

by:ghost8067
Comment Utility
Sonds good. One more question before I screw it up.
How do I split the points?
Jon
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
use the split points link below the last comment
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
on your other q

instead of

interestRateMonthly = (calcValue / 12) / 100;

try:

interestRateMonthly = (calcValue / 12.0) / 100.0;
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 66
countX 22 68
countHi2 challenge 7 43
Checkbox and ListView in Android Layout 4 36
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now