Using input files, one dimensional and two dimensional arrays

Discussion in 'Java' started by madameclaws, Apr 26, 2009.

  1. madameclaws

    madameclaws New Member

    Apr 26, 2009
    Likes Received:
    Trophy Points:
    I'm really frustrated with a program that I am trying to create for my computer science class.
    The program uses a one dimensional array to store names from an input file and then another two dimensional array to store the hours worked of the employees and their pay rate.
    From this, I am supposed to use methods to calculate and store the gross pay, net pay, taxes, and union dues for each of the employees.
    My first problem is importing my name data. I am using a StringTokenizer, which I know for a lot of programmers is very archaic. My teacher is very archaic in a lot of ways. My program code for my method to read the input file is like this looks like this:
          public static int linereader(Scanner inFile, String [] names, double[][] data, int rows)
          { int m = 0;
          StringTokenizer st;
          String line;
          while(rows<30 && inFile.hasNext())
          {line = inFile.nextLine();
           st = new StringTokenizer(line);
           m = st.countTokens();
           names[rows] = st.nextToken();
           for(int j=1; j<m-2; j++)
           { names [rows] = names [rows] + " " + st.nextToken();
             data [rows][5] = Double.parseDouble(st.nextToken());
             data [rows][6] = Double.parseDouble(st.nextToken());
          return rows;
    The problem I am having is that I have names like Smith John L. It can take names like Doe Jane, but nothing beyond 2 tokens. It's really frustrating. :cuss:

    Then I have my first method for calculation. I know this is probably really bad code, but I have no idea what I am doing.:confused: I have been combing the web trying to find something out there about taking data from other columns and calculating them into other columns with two dimensional arrays. Most sites just have the basics on two-dimensional arrays and nothing like what I have to do.
    What I am trying to do is to take the hours that are stored in my 5th column of my array with the pay rate in column 6 and trying to store that in my column 1 of my array. I'm only sending the information to the screen to see if what I am doing is working.
        public static double calculatepay(double [][] data, int rows, int columns)
        {  for (rows=0; rows<30; rows++)
        {  for (columns=0; columns<1; columns++)
           data [rows][1] = data [rows][5] * data [rows][6];
             System.out.println(data [rows][1]);
     }      return data [rows][1];}}
    Any and all help is greatly appreciated.

    Last edited by a moderator: Apr 26, 2009

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice