Java Learner Iteration problem help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thadon
    New Member
    • Feb 2007
    • 3

    #1

    Java Learner Iteration problem help needed

    we are learning java at school and we have to make an applet.

    background info:
    it is appearently so that a person can be devided into four learning types. to find out wich type you are is possible by answering some questions.

    i have to itterate trough 80 odd questions where a user has to answer each one. after answering a question the score of one of the four learing styles has to be incremented.

    the problem:
    i know how to itterate with a switch statement but if i do it the way i know how it will be a lot of work and not very update-able. also i have made 80 string variables in wich i have put the 80 questions this also does not seem very efficient!

    example: (sorry i am duch so my english is not all that i could be ;) )

    switch(intvraag nr)
    {
    case 0: intvraagnr ++;
    intactivist ++;
    strvraag = "Ik neem vaak redelijke risico's als ik het gevoel heb dat het rechtvaardig is";
    break;

    case 1: intvraagnr ++;
    intactivist ++;
    strvraag = ("Ik ben van mening dat formele procedures en voorschriften het gedrag van mensen dwangmatig maakt");
    break;

    case 2: intvraagnr ++;
    inttheoreticus ++;
    strvraag = ("Ik tracht problemen stap voor stap op te lossen en vermijd daarbij iedere vlucht in de fantasie ");
    break;
    }

    i would have to do this for al 80 questions for BOTH the true and false button!!!

    MY QUESTION:

    can somebody maybe help me out with a better way to itterate trough 80 questions and be able to apply a score at the end of it?

    any helpfull reply would be greatly appreciated

    tha don
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by thadon
    we are learning java at school and we have to make an applet.

    background info:
    it is appearently so that a person can be devided into four learning types. to find out wich type you are is possible by answering some questions.

    i have to itterate trough 80 odd questions where a user has to answer each one. after answering a question the score of one of the four learing styles has to be incremented.

    the problem:
    i know how to itterate with a switch statement but if i do it the way i know how it will be a lot of work and not very update-able. also i have made 80 string variables in wich i have put the 80 questions this also does not seem very efficient!

    example: (sorry i am duch so my english is not all that i could be ;) )

    switch(intvraag nr)
    {
    case 0: intvraagnr ++;
    intactivist ++;
    strvraag = "Ik neem vaak redelijke risico's als ik het gevoel heb dat het rechtvaardig is";
    break;

    case 1: intvraagnr ++;
    intactivist ++;
    strvraag = ("Ik ben van mening dat formele procedures en voorschriften het gedrag van mensen dwangmatig maakt");
    break;

    case 2: intvraagnr ++;
    inttheoreticus ++;
    strvraag = ("Ik tracht problemen stap voor stap op te lossen en vermijd daarbij iedere vlucht in de fantasie ");
    break;
    }

    i would have to do this for al 80 questions for BOTH the true and false button!!!

    MY QUESTION:
    can somebody maybe help me out with a better way to itterate trough 80 questions and be able to apply a score at the end of it?

    any helpfull reply would be greatly appreciated

    tha don
    You obviously need an array. But first, how many possible solutions are there for each question? and how do you determine which group to increment given the solution?

    Comment

    • thadon
      New Member
      • Feb 2007
      • 3

      #3
      thanx for replying! you made two very good questions.

      first: How many possible answers

      you can either pick true or false. so true if the statement(quest ion) aplies to you and false if it does not!

      second: how to determen wich group to increment.

      since it is a standard questionaire one of the groups is set to a particular question
      example: question 1 = group 1, question 2 = group 3, question 3 = group 1, question 4 = group 3, ....etc.

      i hope that i have cleared these questions up and if not i will try again just let me know.

      peter.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by thadon
        thanx for replying! you made two very good questions.

        first: How many possible answers

        you can either pick true or false. so true if the statement(quest ion) aplies to you and false if it does not!

        second: how to determen wich group to increment.

        since it is a standard questionaire one of the groups is set to a particular question
        example: question 1 = group 1, question 2 = group 3, question 3 = group 1, question 4 = group 3, ....etc.

        i hope that i have cleared these questions up and if not i will try again just let me know.

        peter.
        The trick lies in how you store the questions for the program. 80 questions is quite a lot so might want to store them in a text file so can do copy paste operations on them easily. The group to increment is stored at the question level i.e for each question, you store also the group for that question. Now you have 4 groups. You might want to create a text file like this

        1.)Are you an idiot?:1
        2.)Are you stupid?:3
        3.)Are you crazy?:4
        etc
        You can save that file as questions.txt.

        Now you then use either Scanner(prefera bly) or BufferedReader( new FileReader("que stions.txt"))

        For each line until all the 80 questions are answered,
        1.) You read a line into a string variable say line.
        2.)You spilt line into two strings question and group. (Use the substring method for this. group is always the last character of line and question is whatever is left after choping off the last 2 characters of line)
        3.)Change group to an integer using Integer.parseIn t


        You now need only 4 cases in your switch. If the response is true, increment an int variable for that group, otherwise go to the next question.

        Comment

        • thadon
          New Member
          • Feb 2007
          • 3

          #5
          Originally posted by r035198x
          The trick lies in how you store the questions for the program. 80 questions is quite a lot so might want to store them in a text file so can do copy paste operations on them easily. The group to increment is stored at the question level i.e for each question, you store also the group for that question. Now you have 4 groups. You might want to create a text file like this

          1.)Are you an idiot?:1
          2.)Are you stupid?:3
          3.)Are you crazy?:4
          etc
          You can save that file as questions.txt.

          Now you then use either Scanner(prefera bly) or BufferedReader( new FileReader("que stions.txt"))

          For each line until all the 80 questions are answered,
          1.) You read a line into a string variable say line.
          2.)You spilt line into two strings question and group. (Use the substring method for this. group is always the last character of line and question is whatever is left after choping off the last 2 characters of line)
          3.)Change group to an integer using Integer.parseIn t


          You now need only 4 cases in your switch. If the response is true, increment an int variable for that group, otherwise go to the next question.

          wow! thanx

          altought i do not fully know all the things you mentioned in your reply i am confident that because now i know of the method i can figure a lot out for myself.

          escpecialy working with a text file is something we haven't handled yet but i am very keen to discover how to work with it.

          anyway thanks for the reply and your help

          peter

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by thadon
            wow! thanx

            altought i do not fully know all the things you mentioned in your reply i am confident that because now i know of the method i can figure a lot out for myself.

            escpecialy working with a text file is something we haven't handled yet but i am very keen to discover how to work with it.

            anyway thanks for the reply and your help

            peter
            Reading a text file is far much easier than storing the questions in an array. It's just
            Code:
             
            BufferedReader reader = new BufferedReader(new FileRader("fileName.txt"));
            Then just read a line using

            Code:
            String line = reder.readLine();
            and you've got the first line of the file in the String line1.

            To make sure you do not try to read after the end og the file then

            Code:
             String line = reder.readLine(); 
            while(line != null) {
              //manipulate the line here
            }

            Comment

            Working...