I am working on a homework assignment where I have to read some annual income numbers from a text file, then determine how much tax is owed assuming the tax bracket is 30%. I am having a couple issues with my code. First: when the message dialog trys to print the array that stores the owed tax it displays "[D@a77106". Second: I have noticed that the code is not reading the first line in the file. I found this out from changing the meassage dialog statement to print only one element of the array i.e. owedTax[1]. Any help would be much appreciated.
Here is the code:
package incomeTax;
import java.io.*;
import javax.swing.JOptionPane; // needed for dialog interaction
public class IncomeTax {
public static void main (String[] args) throws IOException
{
String fileName;
fileName = JOptionPane.showInputDialog("Please enter the file name: ");
ReadIncomeFile(fileName);
}
public static void ReadIncomeFile(String fileName) throws IOException
{
//String userIncome;
try
{
FileReader freader = new FileReader(fileName);
BufferedReader inputFile = new BufferedReader(freader);
String record = null;
double userIncome = 0;
double owedTax[] = new double[fileName.length()];;
for (int index = 0; (record = inputFile.readLine()) != null; index++ ) {
userIncome = Double.parseDouble(record);
owedTax[index] = userIncome * .30;
}
JOptionPane.showMessageDialog(null, owedTax);
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, "file not found");
}
}
}
I have also attached the text file that I have been using to test the code.