Link to home
Create AccountLog in
Avatar of pink16
pink16

asked on

Java error

I receive this error when running my program.  Its a Java Mortgage calculator For school.  The assignment is:
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans. Use an array for the mortgage data for the different loans. Read the interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart. Allow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program.

The program compiles fine and executes, but when it runs I receive this in the command prompt.  Also I am unable to pull loan info from my external file.  My external file has this
7, 0.0535
15, 0.0550
30, 0.0575

The error in the command prompt is this:
java.lang.NumberFormatException: For input string: "0.0535"
        at java.lang.NumberFormatException.forInputString(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at java.lang.Integer.parseInt(Unknown Source)
        at Mort6.load(Mort6.java:94)
        at Mort6.<init>(Mort6.java:72)
        at Mort6$1.run(Mort6.java:425)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
/*
 PRG 421 Java Programming II  Change Request 7, Week 5
 Programmer: Nate Himley
 Date: May 9, 2009
 Filename: Mort6.java
 Purpose: Write the program in Java (with a graphical user interface) and have it calculate and 
 
display the mortgage payment amount from user input of the amount of the mortgage and the user's 
 
selection from a menu of available mortgage loans. Use an array for the mortgage data for the 
 
different loans. Read the interest rates to fill the array from a sequential file. Display the 
 
mortgage payment amount followed by the loan balance and interest paid for each payment over the 
 
term of the loan. Add graphics in the form of a chart. Allow the user to loop back and enter a new 
 
amount and make a new selection or quit. Please insert comments in the program to document the 
 
program.
 */
 
import java.awt.*;
import java.awt.event.*;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.font.*;
import java.awt.Font;
import java.awt.geom.*;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.io.FileReader;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
 
 
public class Mort6 extends JFrame implements ActionListener
{
     JLabel Llabel; 
     JTextField Ltextfield;
     JLabel Olabel;
     JComboBox options;
     JLabel Tlabel;
     JTextField Ttextfield;
     JLabel Rlabel;
     JTextField Rtextfield;
     JLabel Plabel;  
     JLabel $label;  
     JButton calculate;  
     JButton reset;  
     JButton end;  
     JTable table;
     JMenuItem mnuExit = new JMenuItem("Exit");
     DefaultTableModel model;
     int[] trmArray;
     double[] intrstArray;
     JButton graph;
     private float[]  yearlyPrinciple;
     private float[]  yearlyInterest;
 
     // Title
     public Mort6 ()
     {
          super("Nate Himley Week 5");
          setDefaultLookAndFeelDecorated(true);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          load();
          init();
          pack();
          setVisible(true);
     }
 
     //Pull info from file
 
     public void load()
     {
          Reader fis;
               try
               {
 
                    fis = new FileReader("data.txt");
 
                    BufferedReader b = new BufferedReader( fis );
 
                    String[] line = b.readLine(  ).split(",");
                    trmArray = new int[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         trmArray[ i ] = Integer.parseInt(line[i].trim());
                    }
 
                    line = b.readLine(  ).split(",");
                    intrstArray = new double[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         intrstArray[ i ] = Double.parseDouble(line[i].trim());
                    }
 
               b.close();
               fis.close();
               }
 
               catch ( Exception e1 )
               {
                    e1.printStackTrace(  );
               }
     }
 
     //labels, buttons and textfields
 
     public void init()
     {
          Mort6Layout customLayout = new Mort6Layout();
 
          Container con = getContentPane();
          con.setLayout(customLayout);
 
          con.setFont(new Font("Arial", Font.PLAIN, 12));
          con.setLayout(customLayout);
 
          Llabel = new JLabel("Mortgage Loan Amount $ (no comma)");
          con.add(Llabel);
 
          Ltextfield = new JTextField("");//amount textfield
          con.add(Ltextfield);
 
          Olabel = new JLabel("Term & Interest Rate %");
          con.add(Olabel);
 
          options = new JComboBox();
          con.add(options);
 
          options.addItem(" (Preset rate)");
          options.addItem("7 years at 5.35%");
          options.addItem("15 years at 5.5%");
          options.addItem("30 years at 5.75%");
 
          Tlabel = new JLabel("Term (years)");
          con.add(Tlabel);
 
          Ttextfield = new JTextField("");
          con.add(Ttextfield);
 
          Rlabel = new JLabel("Interest Rate");
          con.add(Rlabel);
 
          Rtextfield = new JTextField("");
          con.add(Rtextfield);
 
          Plabel = new JLabel("Monthly Payment Amount");
          con.add(Plabel);
 
          $label = new JLabel("");
          con.add($label);
 
          calculate = new JButton("Calculate");
          con.add(calculate);
          calculate.setBackground(Color.white);
 
          reset = new JButton("Clear");
          con.add(reset);
          reset.setBackground(Color.white);
 
          end = new JButton ("End");
          con.add(end);
          end.setBackground(Color.white);
 
                    //table header names
          String[] columnNames = {"Payment #","Payment Amount", "Interest", "Principle Reduction",
                                             "Remaining Balance"};
 
          //create table and table model
          model = new DefaultTableModel(columnNames, 0);
          table = new JTable(model);
          JScrollPane scroll = new JScrollPane(table);
          table.setPreferredScrollableViewportSize(new Dimension (10, 600));
          con.add (scroll);
 
          graph = new JButton ("See Graph");
          con.add(graph);
          graph.setBackground(Color.white);
 
          //action listeners
          Ltextfield.addActionListener(this); 
          options.addActionListener(this); 
          calculate.addActionListener(this);  
          reset.addActionListener(this); 
          end.addActionListener(this);  
          graph.addActionListener(this);  
     }
 
 
     //action event from listeners
     public void actionPerformed(ActionEvent event)
     {
     Object source = event.getSource();
          if (source == calculate)
          {
               startCalculations();
          }
 
          if (source == reset)
          {
               reset();
          }
 
          if (source==options)
          {
               setRate();
          }
 
          if (source == end)
          {
               exit();
          }
 
          if (source == mnuExit)
          {
            exitGraph();
           }
          if (source == graph)
          {
               mFrame = new JFrame("Mortgage Graph");
               mFrame.getContentPane().add(new GraphPanel(yearlyPrinciple, yearlyInterest));
               mFrame.setSize(800,600);
               mFrame.setLocation(200,100);
 
             //trying to create menu
             // Create an instance of the menu (Creates the Menu Bar)
                 JMenuBar mnuBar = new JMenuBar();
                 mFrame.setJMenuBar(mnuBar);
 
             // Construct and populate the Exit menu (Creates the Exit Menu)
                 JMenu mnuExitbar = new JMenu ("End", true);
                 mnuBar.add(mnuExitbar);
                 mnuExitbar.add(mnuExit);
 
        mFrame.setVisible(true);
 
               //exit listener
                mnuExit.addActionListener(this);  
          }
        }
          public JFrame mFrame = new JFrame();
 
 
void exitGraph()
{
 
             mFrame.dispose();
             mFrame = null;
          }
 
          void setRate()
     {
          int index = options.getSelectedIndex();
 
          //term and interest error check
          if (index > 0)
          {
               try
               {
                    Ttextfield.setText(Integer.toString(trmArray[index-1]));
               }
 
               catch (NumberFormatException e)
               {
                    JOptionPane.showMessageDialog(null, "Invalid or missing Loan Term.  Please try 
 
again!",
                                                            "Message Dialog", 
 
JOptionPane.PLAIN_MESSAGE);
                    Ttextfield.setText(null);
               }
 
               try
               {
                    Rtextfield.setText(Double.toString(intrstArray[index-1]));
               }
 
               catch (NumberFormatException e)
               {
                    JOptionPane.showMessageDialog(null, "Invalid or missing Interest Rate.  Please 
 
try again!",
                                                       "Message Dialog", 
 
JOptionPane.PLAIN_MESSAGE);
                    Rtextfield.setText(null);
               }
          }
     }
 
     //calculation section
     void startCalculations()
     {
          Thread thisThread = Thread.currentThread();
          NumberFormat currency = NumberFormat.getCurrencyInstance();
 
          double amt = 0;
          double trm = 0;
          double intrst = 0;
          double moIn = 0;
          double moTrm = 0;
          double prin = 0;
          double paymt = 0;
 
          //amount error check
          try
          {
               amt = Double.parseDouble(Ltextfield.getText());
          }
 
          catch (NumberFormatException e)
          {
               JOptionPane.showMessageDialog(null, "Missing Amount or Use of Commas",
                                             "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               Ltextfield.setText(null);
               Ttextfield.setText(null);
               Rtextfield.setText(null);
               options.setSelectedIndex(0);
          }
 
          //term and interest error check
          try
          {
               trm = Double.parseDouble(Ttextfield.getText());
 
          }
 
          catch (NumberFormatException e)
          {
               JOptionPane.showMessageDialog(null, "Invalid or missing Loan Term.  Please try 
 
again!",
                                                  "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               Ttextfield.setText(null);
          }
 
          try
          {
               intrst = Double.parseDouble(Rtextfield.getText());
          }
 
          catch (NumberFormatException e)
          {
               JOptionPane.showMessageDialog(null, "Invalid or missing Interest Rate.  Please try 
 
again!",
                                             "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               Rtextfield.setText(null);
          }
 
          if (amt > 0)
          {
               amt = Double.parseDouble(Ltextfield.getText());
               moIn = (intrst / 1200);//monthly interest rate
               moTrm = trm * 12;//number of payments
               paymt = (amt * moIn) / (1-Math.pow((1+moIn), -moTrm));//amount forumla
                  yearlyPrinciple = new float[(int)trm]; // initialize the arrays to store yearly 
 
principle and interest
                  yearlyInterest = new float[(int)trm];
 
               $label.setText("" + currency.format(paymt));
 
               double newPrin = amt;
 
               for (int i = 0; i < trm; i++)
               {
                       yearlyInterest[i] = 0.0f; 
                         yearlyPrinciple[i] = 0.0f; 
                       for(int j = 1; j <=12; j++)
                         {
                    double newIn = moIn * newPrin;
                    double reduct = paymt - newIn;
                         yearlyInterest[i] += newIn; 
                         yearlyPrinciple[i] += reduct; 
                         newPrin = newPrin - reduct;
 
                    
                    if (newPrin < 0)
                         newPrin = 0;
                    else
                         newPrin = newPrin;
 
                    
                    model.addRow(new Object[] { Integer.toString((i*12) + j), 
 
currency.format(paymt),
                    currency.format(newIn), currency.format(reduct), currency.format(newPrin) });
                         }
                        
 //                      model.addRow(new Object[] { Integer.toString(i), currency.format(0.0),
//                    currency.format(yearlyInterest[i]), currency.format(yearlyPrinciple[i]), 
 
currency.format(0.0) });
               }
          }
 
          //less than 0 error check
          if (amt < 0)
          {
               JOptionPane.showMessageDialog(null, "Please Enter Positie Numbers Only.",
                                             "Message Dialog", JOptionPane.PLAIN_MESSAGE);
               Ltextfield.setText(null);
          }
 
     }
 
     //resets all fields
     void reset()
     {
          Ltextfield.setText(null);
          Ttextfield.setText(null);
          Rtextfield.setText(null);
          options.setSelectedIndex(0);
          $label.setText(null);
          model.setRowCount(0);
     }
 
     //exit the program with thank you message
     void exit()
     {
          JOptionPane.showMessageDialog(null, "          Thank you for using \n Mortgage 
 
Calculator",
                                             "Message Dialog", JOptionPane.PLAIN_MESSAGE);
 
          System.exit(0);
     }
 
     public static void main(String args[])
     {
          java.awt.EventQueue.invokeLater(new Runnable()
          {
               public void run()
               {
                    new Mort6().setVisible(true);
               }
          });
     }
}
 
//creates class for container layout and placement
class Mort6Layout implements LayoutManager{
     public Mort6Layout() {}
 
     public void addLayoutComponent(String name, Component comp) {}
 
     public void removeLayoutComponent(Component comp) {}
 
     public Dimension preferredLayoutSize(Container parent)
     {
          Dimension dim = new Dimension(0, 0);
          Insets insets = parent.getInsets();
          dim.width = 600 + insets.left + insets.right;
          dim.height = 425 + insets.top + insets.bottom;
 
          return dim;
     }
 
     public Dimension minimumLayoutSize(Container parent)
     {
          Dimension dim = new Dimension(0, 0);
 
          return dim;
     }
 
     public void layoutContainer(Container parent)
     {
          Insets insets = parent.getInsets();
 
          Component c;
          c = parent.getComponent(0);
               if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+8,250,24);}
          c = parent.getComponent(1);
               if (c.isVisible()) {c.setBounds(insets.left+300,insets.top+8,175,24);}
          c = parent.getComponent(2);
               if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+40,250,24);}
          c = parent.getComponent(3);
               if (c.isVisible()) {c.setBounds(insets.left+300,insets.top+40,150,24);}
          c = parent.getComponent(4);
               if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+72,250,24);}
          c = parent.getComponent(5);
               if (c.isVisible()) {c.setBounds(insets.left+300,insets.top+72,96,24);}
          c = parent.getComponent(6);
               if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+104,250,24);}
          c = parent.getComponent(7);
               if (c.isVisible()) {c.setBounds(insets.left+300,insets.top+104,112,24);}
          c = parent.getComponent(8);
               if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+136,250,24);}
          c = parent.getComponent(9);
               if (c.isVisible()) {c.setBounds(insets.left+300,insets.top+136,112,24);}
          c = parent.getComponent(10);
               if (c.isVisible()) {c.setBounds(insets.left+50,insets.top+168,96,24);}
          c = parent.getComponent(11);
               if (c.isVisible()) {c.setBounds(insets.left+225,insets.top+168,112,24);}
          c = parent.getComponent(12);
               if (c.isVisible()) {c.setBounds(insets.left+400,insets.top+168,96,24);}
          c = parent.getComponent(13);
          if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+200,575,160);}
          c = parent.getComponent(14);
          if (c.isVisible()) {c.setBounds(insets.left+225,insets.top+375,112,24);}
     }
}
 
class GraphPanel extends JPanel
{
    final int
        HPAD = 60,
        VPAD = 40;
    int[] data;
    Font font;
     float[] principleData;
     float[] interestData;
 
 
    public GraphPanel(float[] p, float[] i)
    {
 
     principleData = p;
     interestData = i;
 
        font = new Font("lucida sans regular", Font.PLAIN, 16);
        setBackground(Color.white);
    }
 
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
 
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setFont(font);
        FontRenderContext frc = g2.getFontRenderContext();
        int w = getWidth();
        int h = getHeight();
        // scales
        float xInc = (w - HPAD - VPAD) / (interestData.length - 1);//11f;   
        float yInc = (h - 2*VPAD) / 10f;
        int[] dataVals = getDataVals();        //min and max values for y-axis
        float yScale = dataVals[2] / 10f;
 
        // ordinate (y - axis)
        g2.draw(new Line2D.Double(HPAD, VPAD, HPAD, h - VPAD));
        // plot tic marks
        float x1 = HPAD, y1 = VPAD, x2 = HPAD - 3, y2;
        for(int j = 0; j < 10; j++)
        {
            g2.draw(new Line2D.Double(x1, y1, x2, y1));
            y1 += yInc;
        }
        // labels
        String text; LineMetrics lm;
        float xs, ys, textWidth, height;
        for(int j = 0; j <= 10; j++)
        {
            text = String.valueOf(dataVals[1] - (int)(j * yScale));
            textWidth = (float)font.getStringBounds(text, frc).getWidth();
            lm = font.getLineMetrics(text, frc);
            height = lm.getAscent();
            xs = HPAD - textWidth - 7;
            ys = VPAD + (j * yInc) + height/2;
            g2.drawString(text, xs, ys);
        }
 
        // abcissa (x - axis)
        g2.draw(new Line2D.Double(HPAD, h - VPAD, w - VPAD, h - VPAD));
        // tic marks
        x1 = HPAD; y1 = h - VPAD; y2 = y1 + 3;
        for(int j = 0; j < interestData.length; j++)
        {
            g2.draw(new Line2D.Double(x1, y1, x1, y2));
            x1 += xInc;
        }
        // labels
        ys = h - VPAD;
        for(int j = 0; j < interestData.length; j++)
        {
            text = String.valueOf(j + 1);
            textWidth = (float)font.getStringBounds(text, frc).getWidth();
            lm = font.getLineMetrics(text, frc);
            height = lm.getHeight();
            xs = HPAD + j * xInc - textWidth/2;
            g2.drawString(text, xs, ys + height);
        }
 
        // plot data
          float yy2 = 0, yy1 = 0, xx2 = 0, xx1;
        x1 = HPAD;
          xx1 = HPAD;
        yScale = (float)(h - 2*VPAD) / dataVals[2];
 
        for(int j = 0; j < interestData.length; j++)
        {
          g.setColor(Color.blue);
          y1 = VPAD + (h - 2*VPAD) - (principleData[j] - dataVals[0]) * yScale;
 
            if(j > 0)
            g2.draw(new Line2D.Double(x1, y1, x2, y2));
            x2 = x1;
            y2 = y1;
            x1 += xInc;
 
          g.setColor(Color.red);
          yy1 = VPAD + (h - 2*VPAD) - (interestData[j] - dataVals[0]) * yScale;
               if(j > 0)
            g2.draw(new Line2D.Double(xx1, yy1, xx2, yy2));
            xx2 = xx1;
            yy2 = yy1;
            xx1 += xInc;
 
        }
    }
 
    private int[] getDataVals()
    {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
          int j = interestData.length -1;
          max = (int)principleData[j];
          min = (int)interestData[j];
        int span = max - min;
        return new int[] { min, max, span };
    }
}

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You might have the numbers in the wrong order: you're calling parseInt on a double
You need to call parseInt followed by parseDouble on the same line read that you split
Avatar of yoyo81
yoyo81

There is a problem with the logic here.

read line reads a line at a time. your logic think that readline reads a column at a time.

if you don't know the length of your file, you need to use a dynamically growing data structure to store the mortgages, or continually regrow your array (inefficient)
String[] line = b.readLine(  ).split(",");
                    trmArray = new int[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         trmArray[ i ] = Integer.parseInt(line[i].trim());
                    }
 
                    line = b.readLine(  ).split(",");
                    intrstArray = new double[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         intrstArray[ i ] = Double.parseDouble(line[i].trim());
                    }

Open in new window

for ( int i = 0; i < line.length; i++ )
                    {
                         trmArray[ i ] = Integer.parseInt(line[i].trim());
                    }
You can't call parseint on a decimal.  You need to change trmArray to a double array and rewrite your program in order to use it as a double array.  You'll need this line to be trmArray[i] = Double.parseDouble(line[i].trim());

Good luck
Avatar of pink16

ASKER

Ok I changed trmArray[i] = Double.parseDouble(line[i].trim());
and I can call the first rate and term, but I cant call the other two.
How can I call the external file to read the rows?
Like this
7,5.35
15,5.50
30,5.75
public void load()
     {
          Reader fis;
               try
               {
 
                    fis = new FileReader("data.txt");
 
                    BufferedReader b = new BufferedReader( fis );
 
                    String[] line = b.readLine(  ).split(",");
                    trmArray = new double[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         trmArray[ i ] = Double.parseDouble(line[i].trim());
                    }
 
                    line = b.readLine(  ).split(",");
                    intrstArray = new double[line.length];
                    for ( int i = 0; i < line.length; i++ )
                    {
                         intrstArray[ i ] = Double.parseDouble(line[i].trim());
                    }
 
               b.close();
               fis.close();
               }
 
               catch ( Exception e1 )
               {
                    e1.printStackTrace(  );
               }
     }

Open in new window

All of your code is a bit off.  I'm going to assume that you're only using those 3 lines with no plans to expand this.  If you plan to expand this, then you need to look at the arraylist class and learn about objects that are capable of expanding their size easier than an array. The proper way to do it would be:
try
               {
 
                    fis = new FileReader("data.txt");
 
                    BufferedReader b = new BufferedReader( fis );
                    String inputholder = "";
                    String termsandrates = "";
                    while ((inputholder = b.readLine()) != null)
                    {
                    termsandrates = termsandrates + inputholder;
                    }
                    String[] line = termsandrates.split(",");
                    trmArray = new double[3];
                    trmArray[0] = Double.parseDouble(line[0].trim());
                    trmArray[1] = Double.parseDouble(line[2].trim());
                    trmArray[2] = Double.parseDouble(line[4].trim());
                                   
                    intrstArray = new double[3];
                    intrstArray[0] = Double.parseDouble(line[1].trim());
                    intrstArray[1] = Double.parseDouble(line[3].trim());
                    intrstArray[2] = Double.parseDouble(line[5].trim());
                   
                 
 
               b.close();
               fis.close();
               }

This isn't the greatest way of coding, but it should fix your problem.
Avatar of pink16

ASKER

should I format the file a different way, I still get errors
java.lang.ArrayIndexOutOfBoundsException: 4
        at Mort6.load(Mort6.java:100)
        at Mort6.<init>(Mort6.java:73)
        at Mort6$1.run(Mort6.java:429)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

That was my fault, I left a step out.  Try this instead:
try
               {
 
                    fis = new FileReader("data.txt");
 
                    BufferedReader b = new BufferedReader( fis );
                    String inputholder = "";
                    String termsandrates = "";
                    while ((inputholder = b.readLine()) != null)
                    {
                    termsandrates = termsandrates + "," + inputholder;
                    }
                    String[] line = termsandrates.split(",");
                    trmArray = new double[3];
                    trmArray[0] = Double.parseDouble(line[0].trim());
                    trmArray[1] = Double.parseDouble(line[2].trim());
                    trmArray[2] = Double.parseDouble(line[4].trim());
                                   
                    intrstArray = new double[3];
                    intrstArray[0] = Double.parseDouble(line[1].trim());
                    intrstArray[1] = Double.parseDouble(line[3].trim());
                    intrstArray[2] = Double.parseDouble(line[5].trim());
                   
                 
 
               b.close();
               fis.close();
               }
Avatar of pink16

ASKER

By the way, thank you for all the help
fis = new FileReader("data.txt");

                    BufferedReader b = new BufferedReader( fis );
                    String inputholder = "";
                    String termsandrates = "";
                    while ((inputholder = b.readLine()) != null)
                    {
                    termsandrates = termsandrates + "," + inputholder;
                    }
                    String[] line = termsandrates.split(",");
                    trmArray = new double[3];
                    trmArray[0] = Double.parseDouble(line[0].trim());
                    trmArray[1] = Double.parseDouble(line[2].trim());
                    trmArray[2] = Double.parseDouble(line[4].trim());
                                   
                    intrstArray = new double[3];
                    intrstArray[0] = Double.parseDouble(line[1].trim());
                    intrstArray[1] = Double.parseDouble(line[3].trim());
                    intrstArray[2] = Double.parseDouble(line[5].trim());

               b.close();
               fis.close();
               }

I still get errors
java.lang.NumberFormatException: empty String
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:99
4)
        at java.lang.Double.parseDouble(Double.java:510)
        at Mort6.load(Mort6.java:98)
        at Mort6.<init>(Mort6.java:73)
        at Mort6$1.run(Mort6.java:428)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Mort6.setRate(Mort6.java:283)
        at Mort6.actionPerformed(Mort6.java:217)
        at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1240)
        at javax.swing.JComboBox.setSelectedItem(JComboBox.java:567)
        at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
        at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicCom
boPopup.java:816)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:2
73)
        at java.awt.Component.processMouseEvent(Component.java:6216)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicCombo
Popup.java:480)
        at java.awt.Component.processEvent(Component.java:5981)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4583)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2475)
        at java.awt.Component.dispatchEvent(Component.java:4413)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
ASKER CERTIFIED SOLUTION
Avatar of arrgon
arrgon

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of pink16

ASKER

YOU RULE!!!! That did it, thanks for all your help!!! You made someone smile today.