Solved

Getting error- Can not resolve symbol

Posted on 2004-09-21
7
265 Views
Last Modified: 2010-04-17
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();

      }
}
}
0
Comment
Question by:Harbatuk
  • 3
  • 2
7 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12119067
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");
          }


0
 

Author Comment

by:Harbatuk
ID: 12129877
Thank you!!! This worked. :-)
0
 

Author Comment

by:Harbatuk
ID: 12129908
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();

     }
}
}
0
 
LVL 19

Accepted Solution

by:
drichards earned 125 total points
ID: 12130039
It's not really clear what you're looking for here.  Is it something loke this?  This creates an array of doubles from the file contents.  It doesn't do anything with the values, but that's the easy part.
---------------------
        void ReadWriteTextFile ()
         {
          int fileData;
            try{
                  FileInputStream aFile = new FileInputStream("F:\\Kathy.txt");
                  byte b[] = new byte[64];
                  aFile.read(b);
                    aFile.close();
                    String s = new String(b);
                    String[] vals = s.split(" ");
                    double nums[] = new double[vals.length];
                    for ( int ii = 0; ii < vals.length; ii++)
                    {
                          nums[ii] = Double.parseDouble(vals[ii]);
                    }
              } catch (IOException e) {
                   System.out.print("Could not read file");
              }
-----------------------------------------------
0
 
LVL 19

Expert Comment

by:drichards
ID: 12130049
The previous assumes a single-line file with values separated by spaces.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

11 Experts available now in Live!

Get 1:1 Help Now