Results 1 to 3 of 3

Thread: Please help!

  1. #1
    Asvin is offline Member
    Join Date
    Nov 2010
    Posts
    66
    Rep Power
    0

    Default Please help!

    I have this job assignment program that is giving me errors.. there are two classes:

    a)
    Java Code:
    package workmatrix;
    import java.util.Scanner;
    public class WorkMatrix
    {
        public static void main(String [] args)
        {
            Scanner keyboard = new Scanner (System.in);
            System.out.println("Enter number of people");//Sets # of rows in the matrix
            WorkMatrixMethods.r = keyboard.nextInt();
            System.out.println();
            System.out.println("Enter number of jobs");//Sets # of columns in the matrix
            WorkMatrixMethods.c = keyboard.nextInt();
            System.out.println();
            WorkMatrixMethods group1 = new WorkMatrixMethods();
            group1.readFile();
            group1.arrayCopy();
            group1.bubbleSortRow();
            group1.evaluateRow();
            group1.arrayCopy();
            group1.bubbleSortCol();
            group1.evaluateColumn();
            group1.display();
        }
    }
    The above class is called WorkMatrix

    b)
    Java Code:
    package workmatrix;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.StringTokenizer;
    /**
     * Contains the methods to read and sort a matrix containing the number of hours
     * it takes employees to finish various jobs and then sort those numbers to show the 
     * optimal job for each employee.
     */
    public class WorkMatrixMethods
    {
        /**variable to control # of rows and columns in the matrix*/
        public static int r,c;
        /**array where final values will be stored*/
        private int finalArray[][] = new int [r][c];
        /**temporary array used for sorting*/
        private int tempArray[][] = new int [r][c];
       /**Reads data for the matrix from an Excel file and assigns it to the final array*/
        public void readFile()
        {
            int row = 0, col = 0;
            try
            {
              FileInputStream hours = new FileInputStream ("hours.csv");
              DataInputStream in = new DataInputStream (hours);
              BufferedReader br = new BufferedReader (new InputStreamReader(in));
              String strLine;
              while ((strLine=br.readLine()) != null && row < r && row < c)
              {
                  StringTokenizer st = new StringTokenizer(strLine,",");
                  while (st.hasMoreTokens())
                  {
                      finalArray[row][col] = Integer.parseInt(st.nextToken());
                      col++;
                  }
                  col = 0;
                  row++;
              }
              in.close();
            }
            catch (Exception e)
            {
                System.err.println("Error:" + e.getMessage());
            }
      } 
        /**Sorts rows of temporary array in ascending order*/
        public void bubbleSortRow() 
        {
            for(int i = 0; i < r; i++)
            {
                for(int j = 0; j < c; j++)
                {
                    int out, in, temp;
                    for (out = r - 1; out > 0; out--)
                        for (in = 0; in < out; in++)
                            if (tempArray[i][j] > tempArray[i][in + 1])
                            {
                                temp = tempArray[i][in];
                                tempArray[i][in] = tempArray[i][in+1];
                                tempArray[i][in+1] = temp;
                            }
                }
            }
        }
        /**Sorts columns of temporary array in ascending order*/
        public void bubbleSortCol()
        {
            for(int i = 0; i < r; i++)
            {
                for(int j = 0; j < c; j++)
                {
                    int out, in, temp;
                    for (out = r - 1; out > 0; out--)
                        for (in = 0; in < out; in++)
                            if (tempArray[i][j] > tempArray[in+1][j])
                            {
                                temp = tempArray[i][j];
                                tempArray[i][j] = tempArray[in+1][j];
                                tempArray[in+1][j] = temp;
                            }
                }
            }
        }
        /**Subtracts the smallest integer in row of temporary array from all integers in
          the corresponding row of final array*/
        public void evaluateRow()
        {
            for(int i = 0; i < r; i++)
            {
               for(int j = 0; j < c; j++)
               {
                   finalArray[i][j] -= tempArray[i][0];
               }
            }
        }
        /**Subtracts the smallest integer in row of temporary array from all integers in 
         the corresponding row of final array*/
         public void evaluateColumn() 
         {
             for(int i = 0; i < r; i++)
             {
                 for(int j = 0; j < c; j++)
                 {
                     finalArray[i][j] -= tempArray[0][j];
                 }
             }
        }
       /**Manually copies final array values to a temporary array used for evaluation*/
         public void arrayCopy() 
         {
              for(int i = 0; i < r; i++)
             {
                 for(int j = 0; j < c; j++)
                 {
                    tempArray[i][j]=finalArray[i][j];
                 }
             }
        }
          /**Displays contents of final array*/
         public void display()
        {
           for(int i = 0; i < r; i++)
           {
               for(int j = 0; j < c; j++)
               {
                   System.out.print(finalArray[i][j] + " ");
               }
               System.out.println();
           }
           System.out.println();
        }
    }
    The above class is called WorkMatrixMethods.. the errors it gives me is attached to the thread! Thanks for any help!
    Attached Thumbnails Attached Thumbnails Please help!-workmatrix.png  

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: Please help!

    In future use a meaningful title. You wouldn't be here if you didn't want help.

    Try a clean and build of the project.

  3. #3
    Asvin is offline Member
    Join Date
    Nov 2010
    Posts
    66
    Rep Power
    0

    Default Re: Please help!

    Thanks for replying.. it works like a charm!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •