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.

Results 1 to 2 of 2

Thread: How to begin with multi-dimensional arrays

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to begin with multi-dimensional arrays

    A little backstory: I have some code written by the gentleman before me. I have practically no java experience, but need to make the code that he started work for our new standards. I have NO clue where to even begin, and would love some helpful guidance.

    The code that we have:
    public class employeeSurveyCalculator {
     
      public static void main(String args[]) {
        // Employee answers to the survey
     
        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'}};
     
        // Key to the questions
        char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
     
        // Analyze all answers
        for (int j = 0; j < answers.length; j++) {
     
        // Check one Employee
          int typeOneCount = 0;
          for (int i = 0; i < answers[j].length; i++) {
            if (answers[j][i] == keys[i])
              typeOneCount++;
          } // end for fro j index 
            } // end for for i index
      }// end main method
    } //end class

    We have a survey that we send out to our small teams to check personality compatibility. In particular, we are looking for a certain personality type. These people will be identified by answering the questions a certain way. These answers have been identified and placed in the key array.

    I am supposed to now identify other personality types. This is still in the planning stages, so I have been tasked with expanding this code to create a running count of how many people answer what letter for what question. For example, how many people answer Question 1 with A, with B, with C, etc.

    They tell me this is easy to do, but I am at a complete loss. Can I get some helpful hints to help me on the right track?


    Thank you so much!

    Lorelai


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to begin with multi-dimensional arrays

    count of how many people answer what letter for what question.
    Create an array of int for counting that has the same number of rows as your answers array and the number of columns for all the possible answers including any skipped letters. There must be elements that span from the lowest letter to the highest letter. A and Z require 26 elements.
    Get the question number and answer. Convert the letter to an index for the elements in a column (Hint: you can do arithmetic with char variables: 'B' - 'A' = 1)
    Add one to the counting array indexed by the question number for the row and the column index.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Searching and displaying results in a multi-dimensional array.
    By wfalcon2012 in forum Collections and Generics
    Replies: 2
    Last Post: February 18th, 2012, 08:06 PM
  2. Help with 2 Dimensional Arrays
    By s1mmi in forum Object Oriented Programming
    Replies: 11
    Last Post: February 7th, 2012, 01:43 PM
  3. How can I create a jigsaw puzzle with Array multi-dimensional?
    By ivan8 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: December 4th, 2011, 08:13 PM
  4. Replies: 3
    Last Post: October 26th, 2011, 03:37 PM
  5. Multi Dimensional Array help NEEDED URGENT
    By bonjovi4u in forum Loops & Control Statements
    Replies: 5
    Last Post: February 13th, 2010, 12:44 AM