Link to home
Start Free TrialLog in
Avatar of Harbatuk
Harbatuk

asked on

Getting error- Can not resolve symbol

I am getting an error message "Can not resolve symbol" on line 217 and 219.



//PROGRAMMER:
//CLASS:      
//FILE:       MCEVENT.JAVA
//INSTRUCTOR:
//DATE:            
//PROGRAM DESCRIPTION:
//      Write a Java program using a graphical user interface
//      that calculates and displays the mortgage payment amount
//      from user input of the amount of the mortgage, the term
//      f the mortgage, and the interest rate of the mortgage.
//      Allow the user to loop back and enter new data or quit.
//      Insert comments in the program to document the program.
//      Note: This program was written without a graphical user interface in POS406.
///////////////////////////////////////////////////////////////////////////////////

import javax.swing.*;
import java.awt.event.*;
//import java.awt.lang.*;
import java.text.NumberFormat;       // Number format utility
import java.util.Locale;                  // Local currency format information
import java.io.*;



//INITIALIZAION OF CLASS
//public class mcEvent implements ActionListener,ItemListener, Runnable{
public class mcEvent implements ActionListener,ItemListener{
        MortgageCalculator gui;
        ReadWriteTextFile dosScreen;


        public mcEvent(MortgageCalculator in){
              gui=in;
          }
      public mcEvent(ReadWriteTextFile in2){
         dosScreen=in2;
        }
       // NumberFormat doCurrencyFormat;
       NumberFormat doCurrencyFormat = NumberFormat.getCurrencyInstance(Locale.US);

       public void actionPerformed(ActionEvent event){
             String command = event.getActionCommand();
                   if (command =="Calculate")
                         calculate();
                  else if (command =="Clear")
                     clearAllFields();
                  else if (command =="InterestRate File");
                    ReadWriteTextFile();
                  //else CalcForCheckBoxSelection();
             }

      //CALCULATE METHOD
      void calculate(){

              int termArray=0;
              double termYears=0.0;
              double termRate=0.0;
              double termMonRate=0.0;
              double loanMonths;
              double loanPaymentAmount;
              double countRowNum;
              double principleLoan;
              double interestLoan;
              double principle;
              double loanTime;
              double monInterest;
              double totalInterest=1;
              double totalPrinciple =0.0;
              double actualPrinciple;

              double[][] mortTermData ={ //Choice of mortgage terms
              {7.0,5.35},
              {15.0,5.5},
              {30.0,5.75}
              };
            termArray = gui.cboMortTerm.getSelectedIndex();

            termYears =mortTermData[termArray][0];
            termRate = mortTermData[termArray][1];

            //DETERMINE MONTHLY INTEREST
            termMonRate = termRate/(12*100);

            //GET TOTAL YEARS IN MONTHS
            loanMonths = termYears*12;

            //GET USER ENTRY FROM LOAN AMOUNT TEXTBOX
            principleLoan=Double.parseDouble(gui.tfLoanAmt.getText());

            //CALCULATE LOAN PAYMENT AMOUNT UTILIZING DATA INPUT FROM USER
            loanPaymentAmount = principleLoan*(termMonRate/(1-Math.pow((1 + termMonRate),-loanMonths)));

            //OUTPUT CALCULATIONT TO PAYMENT BOX
            gui.tfMonPayment.setText(doCurrencyFormat.format(loanPaymentAmount));

            countRowNum = gui.amortizModel.getRowCount();
            while(countRowNum >0)
            {
                  gui.amortizModel.removeRow(gui.amortizModel.getRowCount()-1);
                  countRowNum = gui.amortizModel.getRowCount();
            }

            for (int i=1;principleLoan>0;i++)
            {
                  monInterest = principleLoan * termMonRate;
                  principle =loanPaymentAmount -monInterest;
                  actualPrinciple= principleLoan-principle;
                  totalInterest *= monInterest;

                  gui.amortizModel.addRow(new Object[]
                  {String.valueOf(i), doCurrencyFormat.format(loanPaymentAmount)
                  , doCurrencyFormat.format(principle)
               ,doCurrencyFormat.format(monInterest)
                  , doCurrencyFormat.format(actualPrinciple)
                  , doCurrencyFormat.format(totalInterest)});

                  principleLoan = actualPrinciple;
            }

            gui.clearButton.setEnabled(true);
            }
      void CalcForCheckBoxSelection()
      {
             double principle;
             double principleLoan;
              double actualPrinciple;
           double loanAmt=0.0;

             double userMortTerm=0.0;
             double loanMonths;

            double userMortRate=0.0;
              double termMonRate =0.0;
             double monInterest  =0.0;
             double totalInterest=1;

             double loanPaymentAmount;
             int countRowNum;


      //DETERMINE MONTHLY INTEREST
          userMortRate = Double.parseDouble (gui.tfuserMortRate.getText());
            termMonRate = userMortRate/(12*100);

            //GET TOTAL YEARS IN MONTHS
            userMortTerm =Double.parseDouble(gui.tfuserMortTerm.getText());
            loanMonths = userMortTerm*12;

            //GET USER ENTRY FROM LOAN AMOUNT TEXTBOX
            principleLoan=Double.parseDouble(gui.tfLoanAmt.getText());

            //CALCULATE LOAN PAYMENT AMOUNT UTILIZING DATA INPUT FROM USER
            loanPaymentAmount = principleLoan*(termMonRate/(1-Math.pow((1 + termMonRate),-loanMonths)));

            //OUTPUT CALCULATIONT TO PAYMENT BOX
            gui.tfMonPayment.setText(doCurrencyFormat.format(loanPaymentAmount));

            countRowNum = gui.amortizModel.getRowCount();
            while(countRowNum >0)
            {
                  gui.amortizModel.removeRow(gui.amortizModel.getRowCount()-1);
                  countRowNum = gui.amortizModel.getRowCount();
            }

            for (int i=1;principleLoan>0;i++)
            {
                  monInterest = principleLoan * termMonRate;
                  principle =loanPaymentAmount -monInterest;
                  actualPrinciple= principleLoan-principle;
                  totalInterest *= monInterest;

                  gui.amortizModel.addRow(new Object[]
                  {String.valueOf(i), doCurrencyFormat.format(loanPaymentAmount)
                  , doCurrencyFormat.format(principle)
               ,doCurrencyFormat.format(monInterest)
                  , doCurrencyFormat.format(actualPrinciple)
                  , doCurrencyFormat.format(totalInterest)});


      principleLoan = actualPrinciple;
            }




      }
      //CLEAR FIELD METHOD
      void clearAllFields()
      {
         int countRowNum =0;

            //CLEARING ALL FIELD
            gui.tfLoanAmt.setText(null);
            gui.tfMonPayment.setText(null);

            countRowNum= gui.amortizModel.getRowCount();
            while(countRowNum >0)
            {
                  gui.amortizModel.removeRow(gui.amortizModel.getRowCount() - 1);
                  countRowNum = gui.amortizModel.getRowCount();
            }
            gui.clearButton.setEnabled(false);

      }

   //public class ReadWriteTextFile ()
     void ReadWriteTextFile ()
      {
            int fileData;
            File inputFile = new File("C:\\Kathy.txt");

        try{
                  FileInputStream aFile = new FileInputStream(inputFile);
            } catch (IOException e) {
                  System.out.print("Could not read file");
            }
             while((fileData = aFile.read())>0)
                System.out.print((char)fileData);
            aFile.close();

       }

public void itemStateChanged(ItemEvent evt)
      {
            gui.userSelectBox = (JCheckBox)evt.getItemSelectable();
            if (gui.userSelectBox.isSelected()){
              gui.cboMortTerm.setEnabled(false);
              CalcForCheckBoxSelection();            }
            else {
             gui.cboMortTerm.setEnabled(true);

      JComboBox term = (JComboBox)evt.getSource();

      }
}
}
Avatar of drichards
drichards

In the 'ReadWriteTextFile' method, you declare aFile inside a try block and it goes out of scope before you use it.  Try changing:

        try{
               FileInputStream aFile = new FileInputStream(inputFile);
          } catch (IOException e) {
               System.out.print("Could not read file");
          }

to

        FileInputStream aFile;
        try{
               afile = new FileInputStream(inputFile);
          } catch (IOException e) {
               System.out.print("Could not read file");
          }

or move the while inside the try block:

        try{
               FileInputStream aFile = new FileInputStream(inputFile);
               while((fileData = aFile.read())>0)
                  System.out.print((char)fileData);
              aFile.close();
          } catch (IOException e) {
               System.out.print("Could not read file");
          }


Avatar of Harbatuk

ASKER

Thank you!!! This worked. :-)
My next question is......... how do I create this data (from data file)into an array for manipulation.
The data file is named: Kathy.txt.
Contents are very small.  5.37 5.50 5.75

This method is the ReadWriteTextFile();
void ReadWriteTextFile ()
     {
          int fileData;
           File inputFile = new File("C:\\Kathy.txt");
          try{
              FileInputStream aFile = new FileInputStream(inputFile);
              while((fileData = aFile.read())>0)
              System.out.print((char)fileData);
              aFile.close();
           } catch (IOException e) {
              System.out.print("Could not read file");
        }
      }
See below all of the code.


//PROGRAMMER:
//CLASS:      
//FILE:       MCEVENT.JAVA
//INSTRUCTOR:
//DATE:          
//PROGRAM DESCRIPTION:
//     Write a Java program using a graphical user interface
//     that calculates and displays the mortgage payment amount
//     from user input of the amount of the mortgage, the term
//     f the mortgage, and the interest rate of the mortgage.
//     Allow the user to loop back and enter new data or quit.
//     Insert comments in the program to document the program.
//     Note: This program was written without a graphical user interface in POS406.
///////////////////////////////////////////////////////////////////////////////////

import javax.swing.*;
import java.awt.event.*;
//import java.awt.lang.*;
import java.text.NumberFormat;      // Number format utility
import java.util.Locale;               // Local currency format information
import java.io.*;



//INITIALIZAION OF CLASS
//public class mcEvent implements ActionListener,ItemListener, Runnable{
public class mcEvent implements ActionListener,ItemListener{
       MortgageCalculator gui;
       ReadWriteTextFile dosScreen;


       public mcEvent(MortgageCalculator in){
            gui=in;
         }
      public mcEvent(ReadWriteTextFile in2){
        dosScreen=in2;
       }
      // NumberFormat doCurrencyFormat;
      NumberFormat doCurrencyFormat = NumberFormat.getCurrencyInstance(Locale.US);

      public void actionPerformed(ActionEvent event){
            String command = event.getActionCommand();
                if (command =="Calculate")
                     calculate();
               else if (command =="Clear")
                  clearAllFields();
               else if (command =="InterestRate File");
                 ReadWriteTextFile();
               //else CalcForCheckBoxSelection();
           }

     //CALCULATE METHOD
     void calculate(){

            int termArray=0;
            double termYears=0.0;
            double termRate=0.0;
            double termMonRate=0.0;
            double loanMonths;
            double loanPaymentAmount;
            double countRowNum;
            double principleLoan;
            double interestLoan;
            double principle;
            double loanTime;
            double monInterest;
            double totalInterest=1;
            double totalPrinciple =0.0;
            double actualPrinciple;

            double[][] mortTermData ={ //Choice of mortgage terms
            {7.0,5.35},
            {15.0,5.5},
            {30.0,5.75}
            };
          termArray = gui.cboMortTerm.getSelectedIndex();

          termYears =mortTermData[termArray][0];
          termRate = mortTermData[termArray][1];

          //DETERMINE MONTHLY INTEREST
          termMonRate = termRate/(12*100);

          //GET TOTAL YEARS IN MONTHS
          loanMonths = termYears*12;

          //GET USER ENTRY FROM LOAN AMOUNT TEXTBOX
          principleLoan=Double.parseDouble(gui.tfLoanAmt.getText());

          //CALCULATE LOAN PAYMENT AMOUNT UTILIZING DATA INPUT FROM USER
          loanPaymentAmount = principleLoan*(termMonRate/(1-Math.pow((1 + termMonRate),-loanMonths)));

          //OUTPUT CALCULATIONT TO PAYMENT BOX
          gui.tfMonPayment.setText(doCurrencyFormat.format(loanPaymentAmount));

          countRowNum = gui.amortizModel.getRowCount();
          while(countRowNum >0)
          {
               gui.amortizModel.removeRow(gui.amortizModel.getRowCount()-1);
               countRowNum = gui.amortizModel.getRowCount();
          }

          for (int i=1;principleLoan>0;i++)
          {
               monInterest = principleLoan * termMonRate;
               principle =loanPaymentAmount -monInterest;
               actualPrinciple= principleLoan-principle;
               totalInterest *= monInterest;

               gui.amortizModel.addRow(new Object[]
               {String.valueOf(i), doCurrencyFormat.format(loanPaymentAmount)
               , doCurrencyFormat.format(principle)
             ,doCurrencyFormat.format(monInterest)
               , doCurrencyFormat.format(actualPrinciple)
               , doCurrencyFormat.format(totalInterest)});

               principleLoan = actualPrinciple;
          }

          gui.clearButton.setEnabled(true);
          }
     void CalcForCheckBoxSelection()
     {
           double principle;
            double principleLoan;
            double actualPrinciple;
          double loanAmt=0.0;

           double userMortTerm=0.0;
           double loanMonths;

           double userMortRate=0.0;
            double termMonRate =0.0;
           double monInterest  =0.0;
           double totalInterest=1;

           double loanPaymentAmount;
           int countRowNum;


     //DETERMINE MONTHLY INTEREST
         userMortRate = Double.parseDouble (gui.tfuserMortRate.getText());
          termMonRate = userMortRate/(12*100);

          //GET TOTAL YEARS IN MONTHS
          userMortTerm =Double.parseDouble(gui.tfuserMortTerm.getText());
          loanMonths = userMortTerm*12;

          //GET USER ENTRY FROM LOAN AMOUNT TEXTBOX
          principleLoan=Double.parseDouble(gui.tfLoanAmt.getText());

          //CALCULATE LOAN PAYMENT AMOUNT UTILIZING DATA INPUT FROM USER
          loanPaymentAmount = principleLoan*(termMonRate/(1-Math.pow((1 + termMonRate),-loanMonths)));

          //OUTPUT CALCULATIONT TO PAYMENT BOX
          gui.tfMonPayment.setText(doCurrencyFormat.format(loanPaymentAmount));

          countRowNum = gui.amortizModel.getRowCount();
          while(countRowNum >0)
          {
               gui.amortizModel.removeRow(gui.amortizModel.getRowCount()-1);
               countRowNum = gui.amortizModel.getRowCount();
          }

          for (int i=1;principleLoan>0;i++)
          {
               monInterest = principleLoan * termMonRate;
               principle =loanPaymentAmount -monInterest;
               actualPrinciple= principleLoan-principle;
               totalInterest *= monInterest;

               gui.amortizModel.addRow(new Object[]
               {String.valueOf(i), doCurrencyFormat.format(loanPaymentAmount)
               , doCurrencyFormat.format(principle)
             ,doCurrencyFormat.format(monInterest)
               , doCurrencyFormat.format(actualPrinciple)
               , doCurrencyFormat.format(totalInterest)});


     principleLoan = actualPrinciple;
          }




     }
     //CLEAR FIELD METHOD
     void clearAllFields()
     {
        int countRowNum =0;

          //CLEARING ALL FIELD
          gui.tfLoanAmt.setText(null);
          gui.tfMonPayment.setText(null);

          countRowNum= gui.amortizModel.getRowCount();
          while(countRowNum >0)
          {
               gui.amortizModel.removeRow(gui.amortizModel.getRowCount() - 1);
               countRowNum = gui.amortizModel.getRowCount();
          }
          gui.clearButton.setEnabled(false);

     }

   //public class ReadWriteTextFile ()
     void ReadWriteTextFile ()
     {
          int fileData;
           File inputFile = new File("C:\\Kathy.txt");
          try{
              FileInputStream aFile = new FileInputStream(inputFile);
              while((fileData = aFile.read())>0)
              System.out.print((char)fileData);
              aFile.close();
           } catch (IOException e) {
              System.out.print("Could not read file");
        }
      }

public void itemStateChanged(ItemEvent evt)
     {
          gui.userSelectBox = (JCheckBox)evt.getItemSelectable();
          if (gui.userSelectBox.isSelected()){
            gui.cboMortTerm.setEnabled(false);
            CalcForCheckBoxSelection();          }
          else {
           gui.cboMortTerm.setEnabled(true);

     JComboBox term = (JComboBox)evt.getSource();

     }
}
}
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The previous assumes a single-line file with values separated by spaces.