0
public static FAQ_Alisa_QnA[] oipReadQuestion(){
        String questionA1,thisUser;
        int indexQuestion;
        String [] entryDetails;
        FAQ_Alisa_QnA [] entries = new FAQ_Alisa_QnA[100];
        //Read file = "activities.txt".
        File file = new File ("ReadOIP.txt");
        int count = 0;

        try{
            Scanner sc = new Scanner(file);
            //do this while there is a next line in file.
            while(sc.hasNextLine()){
                String line = sc.nextLine();
                entryDetails = line.split(";");

                //              index = entryDetails[0];

                indexQuestion = Integer.parseInt(entryDetails[0]);
                thisUser = entryDetails[1];
                questionA1 = entryDetails[2];


                //Object to store values of entry.
                FAQ_Alisa_QnA a = new FAQ_Alisa_QnA();

                //              a.index = Integer.parseInt(index);
                a.indexQuestion = indexQuestion;
                a.thisUsername = thisUser;
                a.questionA1 = questionA1;

                entries [count] = a;
                count++;
            }
        }catch(FileNotFoundException fnfe){
            System.out.println(fnfe.getMessage());
        }
        FAQ_Alisa_QnA [] allQuestions = new FAQ_Alisa_QnA [count];

        for(int i = 0; i < count; i++){

            allQuestions[i] = entries[i];
        }
        return allQuestions;
    }
    public static FAQ_Alisa_QnA[] oipReadAnswers(){
        String indexAnswer, answer11, thisUser;
        String [] answerDetails;
        FAQ_Alisa_QnA [] answers = new FAQ_Alisa_QnA[100];
        //Read file = "activities.txt".
        File thisFile = new File ("AnsReadOIP.txt");
        int count1 = 0;

        try{
            Scanner sc1 = new Scanner(thisFile);
            //do this while there is a next line in file.
            while(sc1.hasNextLine()){
                String line = sc1.nextLine();
                answerDetails = line.split(";");

                //              index = entryDetails[0];
                indexAnswer = answerDetails[0];
                thisUser = answerDetails[1];
                answer11 = answerDetails[2];


                //Object to store values of entry.
                FAQ_Alisa_QnA a = new FAQ_Alisa_QnA();

                //              a.index = Integer.parseInt(index);

                a.indexAnswer = Integer.parseInt(indexAnswer);
                a.thisUsername = thisUser;
                a.answer11 = answer11;

                answers [count1] = a;
                count1++;
            }
        }catch(FileNotFoundException fnfe){
            System.out.println(fnfe.getMessage());
        }
        FAQ_Alisa_QnA[] allAnswers = new FAQ_Alisa_QnA[count1];

        for(int i = 0; i < count1; i++){

            allAnswers[i] = answers[i];

        }
        return allAnswers;
    }
    public static void oipPrintQnA(){

        FAQ_Alisa_QnA [] allQuestions   =  oipReadQuestion();
        FAQ_Alisa_QnA [] allAnswers = oipReadAnswers();


        System.out.println("Organization in project work");
        System.out.println("=============================");
        for(int i = 0; i < allQuestions.length; i++){
            System.out.println( allQuestions[i].indexQuestion + "-" + "Question" + ":");
            System.out.println(allQuestions[i].thisUsername + ":" +allQuestions[i].questionA1);
            System.out.println("                ");
            for(int j = 0; j < allAnswers.length; j++){
                if(allQuestions[i].indexQuestion == allAnswers[j].indexAnswer){
                    System.out.println("Answer for question "+ + allAnswers[j].indexAnswer+ ":" );
                    System.out.println(allAnswers[j].thisUsername+ ":" +allAnswers[j].answer11);
                    System.out.println("                ");

                }
            }
        }

    }

//So I have read answers and questions and I saved my qns and answers in 2 different text files. This is because I have add functions to it but i never put it here cuz my qn is not related to that. I just wanna know how to print out the qn and answer in 2 lines so that if the qn is so long then it can print out in two lines//

So these are how my text files look like: ReadOIP.txt

1;Shafiq;How to organize your time well when you're juggling with so many project work and assignments on the same day? Best answer:The best solution to this is to early planning or schedule your time wisely. Write in a calendar beforehand the work you are going to do for an assignment. 2;Rohannah;Does having a timetable works to finish your project on time? 3;lymeoww;Is task allocation really important to be organized in project work?

AnsReadOIP.txt

1;Andy23;The best solution to this is to early planning or schedule your time wisely. Write in a calendar beforehand the work you are going to do for an assignment .2; Does having a timetable to do your project works? //For example this line, it will print out very long on the console// 2;Betty23;of course it does! 1;Ying Qian;just organize lorh 3;lymeoww;Yes, it is important!

//Refer to this picture//

  • just add word wrap on your console or if so necessary, use a character stream and when hit # of characters add a \n – Javant Aug 08 '16 at 14:41
  • Hey hi, thanks for the reply. I'm very new to programming and i don't get what's word wrap or character stream. I tried googling too and dont get it – alisa fathima Aug 08 '16 at 14:49
  • Reading chars http://stackoverflow.com/questions/811851/how-do-i-read-input-character-by-character-in-java – Javant Aug 08 '16 at 14:55
  • When I say limiting redundant calls I mean something like, //Dont String word; if(word.Length == 0) //do something if(word.Length == 10) //do something ... //Do String word; int length = word.Length; if(length == 0) //do something if(length == 10) // do something length – Javant Aug 08 '16 at 14:55

0 Answers0