Solved

Getting error- Can not resolve symbol

Posted on 2004-09-21
7
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

737 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