Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 38 of 38

Thread: Two-Dimensional Array to Grade Students?

  1. #26
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    For the if statements, look at the brackets in which the for loop is running.
    As for the students grades, are you saying that each student has a unique grade? Ex. Student 1 has 6, and student 2 has 8. Could we not just say, student 1 has 8, and student 2 has 6 considering the students don't have names? If not, let me know. I'll work through it with you
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  2. The Following User Says Thank You to vanDarg For This Useful Post:

    Java Neil (March 22nd, 2011)

  3. #27
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Quote Originally Posted by vanDarg View Post
    For the if statements, look at the brackets in which the for loop is running.
    As for the students grades, are you saying that each student has a unique grade? Ex. Student 1 has 6, and student 2 has 8. Could we not just say, student 1 has 8, and student 2 has 6 considering the students don't have names? If not, let me know. I'll work through it with you
    Yes, each student has a unique grade and needs to sort with their perspective student.

    I now see what you mean about the brackets.

    Here is the fixed code

       import javax.swing.JOptionPane;
       public class GradeExam {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[] student = new int[8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
                   student[i] = correctCount;           		    
                } 	
     
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
             }               
           //Find the maximum in the list
             for (int i = student.length - 1; i > 0; i--) {          
                int currentMax = student[i];
                int currentMaxIndex = i;          
     
                for (int j = i - 1; j > (-1); j--) {
                   if (currentMax < student[j]) {
                      currentMax = student[j];
                      currentMaxIndex = j;
                   }
                }
     
              //Swap student[i] with list[currentMinIndex] if necessary
                if (currentMaxIndex != i) {
                   student[currentMaxIndex] = student[i];
                   student[i] = currentMax;
                }
             } 
     
           //Convert input to a String
             String result3 = "The students sorted scores: \n" + "\n";
             for (int i = 0; i < student.length; i++) {
                result3 += "Student " + (i + 1) + "'s score = " + student[i] + " \n";            
             }     
     
           //Display the sorted grades
             JOptionPane.showMessageDialog(null, result3);
     
             JOptionPane.showMessageDialog(null, "Thanks for playing!");
          }   
       }

    The only thing left is tying the students to their grades.

    Once again, I can't thank you enough for your help.
    Last edited by Java Neil; March 21st, 2011 at 11:45 PM.

  4. #28
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    I'm not sure if this helps, but here is some code that will sort two values.

    public class SortTwoDimensions {
      public static void main(String[] args) {
        int m[][] = { { 4, 2 }, { 1, 7 }, { 4, 5 }, { 1, 2 }, { 1, 1 }, { 4, 1 } };
     
        sort(m);
     
        printArray(m);
      }
     
      public static void sort(int m[][]) {
        for (int i = 0; i < m.length; i++) {
          double currentMin = m[i][0];
          int currentMinIndex = i;
     
          for (int j = i; j < m.length; j++) {
            if (currentMin > m[j][0] // primary sort
                || (currentMin == m[j][0] && m[currentMinIndex][1] > m[j][1])) // secondary
                                                                                // sort
            {
              currentMin = m[j][0];
              currentMinIndex = j;
            }
          }
     
          // Swap list[i] with list[currentMinIndex] if necessary;
          if (currentMinIndex != i) {
            int temp0 = m[currentMinIndex][0];
            int temp1 = m[currentMinIndex][1];
            m[currentMinIndex][0] = m[i][0];
            m[currentMinIndex][1] = m[i][1];
            m[i][0] = temp0;
            m[i][1] = temp1;
          }
        }
      }
     
      public static void printArray(int m[][]) {
        for (int i = 0; i < m.length; i++) {
          System.out.println(m[i][0] + ", " + m[i][1]);
        }
      }
    }

    Now if we use this type of sort, I guess the students correctCount would be the primary sort and the student would be the secondary.

    What do you think?

  5. #29
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Wow, my brain hurts!

    Well this is the combination of the codes.

       import javax.swing.JOptionPane;
       public class GradeExam {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[][] student = new int[8][8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
     
     
                } 	
                student[i][0] = correctCount; 
                student[i][1] = i;
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
                sort(student);
     
                printArray(student);
             }
          }
          public static void sort(int m[][]) {
             for (int i = 0; i < m.length; i++) {
                double currentMin = m[i][0];
                int currentMinIndex = i;
     
                for (int j = i; j < m.length; j++) {
                   if (currentMin > m[j][0] // primary sort
                   || (currentMin == m[j][0] && m[currentMinIndex][1] > m[j][1])) // secondary
                                                                                // sort
                   {
                      currentMin = m[j][0];
                      currentMinIndex = j;
                   }
                }
     
             // Swap list[i] with list[currentMinIndex] if necessary;
                if (currentMinIndex != i) {
                   int temp0 = m[currentMinIndex][0];
                   int temp1 = m[currentMinIndex][1];
                   m[currentMinIndex][0] = m[i][0];
                   m[currentMinIndex][1] = m[i][1];
                   m[i][0] = temp0;
                   m[i][1] = temp1;
                }
             }
          }
     
          public static void printArray(int m[][]) {
             String result3 = "The students sorted scores: \n" + "\n";
             for (int i = 0; i < m.length; i++) {
                result3 += "Student " + (m[i][1]+1) + "'s score = " + m[i][0] + " \n";
     
             }
             JOptionPane.showMessageDialog(null, result3);
          }
       }

    While this code kinda works the way I want it to, it does not hold all the values. It sorts the first four students with their grades, but after that it will replace previous students and their grades with new ones.

    Another problem with this code is I only want it to print the sorted grades once, and this prints every cycle?

    I'm soooooo close I can taste it. It's scary to say, but I'm starting to love Java!

  6. #30
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Here is one without all the methods...

       import javax.swing.JOptionPane;
       public class GradeExam {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[][] student = new int[8][8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
                   student[i][0] = correctCount; 
                   student[i][1] = i;
     
                } 	
     
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
             }
             for (int i = 0; i < student.length; i++) {
                double currentMin = student[i][0];
                int currentMinIndex = i;
     
                for (int j = i; j < student.length; j++) {
                   if (currentMin > student[j][0] // primary sort
                   || (currentMin == student[j][0] && student[currentMinIndex][1] > student[j][1])) // secondary
                                                                                // sort
                   {
                      currentMin = student[j][0];
                      currentMinIndex = j;
                   }
                }
     
             // Swap list[i] with list[currentMinIndex] if necessary;
                if (currentMinIndex != i) {
                   int temp0 = student[currentMinIndex][0];
                   int temp1 = student[currentMinIndex][1];
                   student[currentMinIndex][0] = student[i][0];
                   student[currentMinIndex][1] = student[i][1];
                   student[i][0] = temp0;
                   student[i][1] = temp1;
               }
     
                String result3 = "The students sorted scores: \n" + "\n";
                for (i = 0; i < student.length; i++) {
                   result3 += "Student " + (student[i][1]+1) + "'s score = " + student[i][0] + " \n";
     
                }
                JOptionPane.showMessageDialog(null, result3);
             }
          }
       }

    This code prints correctly and has all the values in it, but it's not sorting correctly. The students are printed with their grades but not in the right order. I can tell that there is some sorting being done, but I can't see the logic behind it.

  7. #31
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Looking good, I did not realize that you had to sort the grades in such a way. So, using a multi-dimensional array here is a good idea. I think you need to look a little closer at the sorting algorithm. See this link on sorting a multi-dimensional array. I also recommend (and it isn't necessary) removing the sorting part of your code and place it into a separate method, this will add to the organization and readability.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  8. #32
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Quote Originally Posted by vanDarg View Post
    Looking good, I did not realize that you had to sort the grades in such a way. So, using a multi-dimensional array here is a good idea. I think you need to look a little closer at the sorting algorithm. See this link on sorting a multi-dimensional array. I also recommend (and it isn't necessary) removing the sorting part of your code and place it into a separate method, this will add to the organization and readability.
    Thanks for the tips. I've posted so many codes, I'm not sure which one you're referring to. About three posts ago I posted code that had separate methods.

    Could you maybe show me what you had in mind. It's just that my class starts in about an hour and I might not have time to work through the logic. I would not normally ask, but I'll learn the process just the same just as I did when you showed me the other stuff.

  9. #33
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Quote Originally Posted by Java Neil View Post
    Wow, my brain hurts!

    Well this is the combination of the codes.

       import javax.swing.JOptionPane;
       public class GradeExam {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[][] student = new int[8][8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
     
     
                } 	
                student[i][0] = correctCount; 
                student[i][1] = i;
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
                sort(student);
     
                printArray(student);
             }
          }
          public static void sort(int m[][]) {
             for (int i = 0; i < m.length; i++) {
                double currentMin = m[i][0];
                int currentMinIndex = i;
     
                for (int j = i; j < m.length; j++) {
                   if (currentMin > m[j][0] // primary sort
                   || (currentMin == m[j][0] && m[currentMinIndex][1] > m[j][1])) // secondary
                                                                                // sort
                   {
                      currentMin = m[j][0];
                      currentMinIndex = j;
                   }
                }
     
             // Swap list[i] with list[currentMinIndex] if necessary;
                if (currentMinIndex != i) {
                   int temp0 = m[currentMinIndex][0];
                   int temp1 = m[currentMinIndex][1];
                   m[currentMinIndex][0] = m[i][0];
                   m[currentMinIndex][1] = m[i][1];
                   m[i][0] = temp0;
                   m[i][1] = temp1;
                }
             }
          }
     
          public static void printArray(int m[][]) {
             String result3 = "The students sorted scores: \n" + "\n";
             for (int i = 0; i < m.length; i++) {
                result3 += "Student " + (m[i][1]+1) + "'s score = " + m[i][0] + " \n";
     
             }
             JOptionPane.showMessageDialog(null, result3);
          }
       }

    While this code kinda works the way I want it to, it does not hold all the values. It sorts the first four students with their grades, but after that it will replace previous students and their grades with new ones.

    Another problem with this code is I only want it to print the sorted grades once, and this prints every cycle?

    I'm soooooo close I can taste it. It's scary to say, but I'm starting to love Java!
    This is the code with the methods. As you can see I have a few problems with it!

  10. #34
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    I was referring to your most recent post. You don't have to move the sorting into a method, it was just a suggestion. Work on the sorting.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  11. #35
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Quote Originally Posted by vanDarg View Post
    I was referring to your most recent post. You don't have to move the sorting into a method, it was just a suggestion. Work on the sorting.
    Yeah, That's the code I'm messing with but I'm running out of time fast!

       import javax.swing.JOptionPane;
       public class GradeExam2 {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[][] student = new int[8][8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
                   student[i][0] = correctCount; 
                   student[i][1] = i;
     
                } 	
     
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
             }
             for (int i = 0; i < student.length; i++) {
                double currentMin = student[i][0];
                int currentMinIndex = i;
     
                for (int j = i; j < student.length; j++) {
                   if (currentMin > student[j][0] // primary sort
                   || (currentMin == student[j][0] && student[currentMinIndex][1] > student[j][1])) // secondary
                                                                                // sort
                   {
                      currentMin = student[j][0];
                      currentMinIndex = j;
                   }
                }
     
             // Swap list[i] with list[currentMinIndex] if necessary;
                if (currentMinIndex != i) {
                   int temp0 = student[currentMinIndex][0];
                   int temp1 = student[currentMinIndex][1];
                   student[currentMinIndex][0] = student[i][0];
                   student[currentMinIndex][1] = student[i][1];
                   student[i][0] = temp0;
                   student[i][1] = temp1;
               }
     
                String result3 = "The students sorted scores: \n" + "\n";
                for (i = 0; i < student.length; i++) {
                   result3 += "Student " + (student[i][1]+1) + "'s score = " + student[i][0] + " \n";
     
                }
                JOptionPane.showMessageDialog(null, result3);
             }
          }
       }

  12. #36
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Well I've tried everything time will allow, but it's time for class. When I get to school I'll check back to see if you have come up with something. Even if you can't, I value everything you have done for me. I truly am learning a lot about the "proper way" to do things in java.

    If you're not already planning it, you should become a moderator here.

  13. #37
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Thanks for your confidence, I'd follow that link I provided on sorting multi-dimensional arrays, this should get your code to where you need it.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  14. #38
    Member Java Neil's Avatar
    Join Date
    Jan 2011
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Two-Dimensional Array to Grade Students?

    Quote Originally Posted by vanDarg View Post
    Thanks for your confidence, I'd follow that link I provided on sorting multi-dimensional arrays, this should get your code to where you need it.
    The good news is my teacher checked off this assignment. He didn't even look at whether or not the students were being sorted with the grades. The bad news is I now need to figure this out to satisfy my own knowledge of this kind of thing.

    So here is the program with the link's you provided me code mixed in. It in no way is working yet (I have not set it up to call anything yet). I thought you might be able to take it as it is and write some note for me as far as structure is concerned. Once again I think I need to learn the proper way, rather than just what works.

       import javax.swing.JOptionPane;
       public class GradeExam2 {
          public static void main(String[] args) {
             char[][] answers = {
                   {'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},
                   {'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D'},
                   {'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D'},
                   {'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
                   {'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D'}}; 	
     
             char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};       
     
           //Create new array to sort students
             int[][] student = new int[8][8];
     
           //Echo the answers
             String result = "The answer key to the test: \n";
             for (int k = 0; k < 10; k++) {
                result += keys[k] + " ";
     
             }
             for (int i = 0; i < answers.length; i++) {
                int correctCount = 0;
              //Convert grades to a String
                String result2 = "Student " + (i + 1) + "'s answers are: \n";
                for (int j = 0; j < answers[i].length; j++) {
                   result2 += answers[i][j] + " ";
                   if (answers[i][j] == keys[j])
                      correctCount++;
                   student[i][0] = correctCount; 
                   student[i][1] = i;
     
                } 	
     
              //Display the input
                JOptionPane.showMessageDialog(null, result + "\n" + result2 +        
                   "\nStudent " + (i + 1) + "'s correct count is " + correctCount);                 
             }
          }
     
          private String[][] bubbleSortMulti(String[][] MultiIn, int compIdx) {
     
             String[][] temp = new String[MultiIn.length][MultiIn[0].length];
     
             boolean finished = false;
     
             while (!finished) { 
                finished = true; 
     
                for (int i = 0; i < MultiIn.length - 1; i++) { 
     
                   if (MultiIn[i][compIdx].compareToIgnoreCase(MultiIn[i + 1][compIdx]) > 0) { 
     
                      for (int j = 0; j < MultiIn[i].length; j++) { 
                         temp[i][j] = MultiIn[i][j]; 
                         MultiIn[i][j] = MultiIn[i + 1][j]; 
                         MultiIn[i + 1][j] = temp[i][j]; }
     
                      finished = false; 
                   } 
                } 
             } 
             return MultiIn; 
          } 
       }

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Single Dimensional Array Help!
    By Allicat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 15th, 2011, 01:01 PM
  2. Two-Dimensional Array and Loops
    By astrojunk in forum Java Theory & Questions
    Replies: 2
    Last Post: February 11th, 2011, 07:18 AM
  3. 2 dimensional array alternative ???
    By zeeshanmirza in forum Java SE APIs
    Replies: 1
    Last Post: February 23rd, 2010, 06:18 PM
  4. Grade Array Trouble
    By kite98765 in forum Collections and Generics
    Replies: 3
    Last Post: January 7th, 2010, 08:14 PM
  5. Grade averaging program with array and multiple methods.
    By jeremykatz in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 9th, 2009, 09:44 PM