Java

79 views
Skip to first unread message

dimplech...@gmail.com

unread,
Apr 21, 2015, 1:59:26 PM4/21/15
to jugch...@googlegroups.com
Hi, I am trying to do this for an assignment but have no idea how to implement it with Java.

There is a text file with some multiple choice questions and answers, these represent flashcards, such that the Q and A1, A2, A3,..., Ak are enclosed between spaces (if there is more than one question).

For example:

What is the Capital of British Columbia
Victoria // correct answer is always the first m/c
Coquitlam
Richmond
Vancouver
//space
Another question
with its answers
//space
etc

I would like to store the Question, and consecutive answers into a string array until it reaches the space (indicating the end of the flashcard).
However, since there are several questions with no specific amount of answers (thus the Akth answer), this array must be able to grow and shrink.

I was thinking of the following:

Java Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
       //create array
       Array[] cards;
 
       //create index for counting lines and another index for counting array slots
       int arrayindex;
       int textindex;
 
while (scan.hasNext() == true) {
    String lineOfText = scan.nextLine() ;
    if (lineOfText.length() == 0) {
        continue ; //until find a textline
                
 
                //somehow store text until arriving at space?!?!?!
         
    }

Ravi Sankar J

unread,
Apr 21, 2015, 10:03:49 PM4/21/15
to jugch...@googlegroups.com

Hi

Use collections instead of array.

Thanks
RAVISANKAR

--
You received this message because you are subscribed to the Google Groups "Java User Group - Chennai" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jugchennai+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

george antony

unread,
Apr 21, 2015, 10:15:44 PM4/21/15
to jugch...@googlegroups.com
Hi Dimple,
Use ArrayList instead of plain Array. You need not give fixed size for ArrayList,it can add any number of elements.


--
Reply all
Reply to author
Forward
0 new messages