I been trying to import the list in the text file to the word doc, the thing is, is that I can only get the last line on the text imported while I'm missing the rest of the top. Can somebody help please?

import java.util.Scanner;
   import java.io.*;
   import java.util.*;
    public class Lab3{
       public static void main (String [] args) throws Exception {
         int i;
         int j;
         File file = new java.io.File("employeedata.txt");
      //Scanner input = new Scanner(file);
      //create  a scanner for input
         Scanner input = new java.util.Scanner(file);
      //make a string array
         String [][] empId = new String [8][6];
      //a while loop that makes the table
         while(input.hasNext()){
            for(i=0;i<8;i++){
               for(j=0;j<6;j++){
               
                  empId[i][j]= input.next();
               //reads the table from left to right
                  String lastName = input.next();
                  String firstName = input.next();
                  float hour = input.nextFloat();
                  float pay =input.nextFloat();
               //calculations
                  double gross = hour * pay;
                  double federal = gross * (.09 / 100);
                  double state = gross * (.07 / 100);
                  double totalDeductions = federal + state;
                  double net = gross - totalDeductions;
               //displays the results
                 // System.out.println(empId[i][j] + "        " + lastName + "         " + firstName + "        " + hour + "       " + pay + "        " + net);
                  java.io.File output = new java.io.File("payroll.doc");
						java.io.PrintWriter outfile = new java.io.PrintWriter(output);
						outfile.println(empId[i][j] + "        " + lastName + "         " + firstName + "        " + hour + "       " + pay + "        " + net);
						//if(i == 6 && j == 8
						outfile.close();
						
               }
            }
         }
         input.close();
      }
   }

employeedata.txt
1000220 PoppinFresh John 45 13.50
1000221 Jackson Michael 38 8.50
1000222 Smoove Willie 42 15.00
1000223 Rothelisberger Ben 50 17.80
1000224 Gangstalicious Manny 30 6.50
1000225 Nawtinclass Nikki 55 6.55
1000226 Peyatenshun Didnat 16 5.95
1000227 Ovaslept Olivia 13 5.58

Member Avatar for iamthwee

Why are you using a 2d array?

A class would be perfect here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.