Hello there. I've been contemplating on this matter for sometime, and now I'm left stumped. I'm a college student taking a Java 2 course, and was given an assignment that i've nearly completed except one problem. The program description asks you to read from a binary file using the .readUTF(); class and then stick the information in their proper arrays. What is in the binary bit file is 10 peoples' names, their sex, and their 5 grade scores. An example of the binary file looks like the such: Marry James:F;50,60,100,90,80

Here's a small portion of my code that shows you how I've extracted the information.

   do
     {

        record = data_in.readUTF();
   int a = record.indexOf(' ',0);  // finds the number of which the first space is printed
   name1[cc] = record.substring(0,a); // puts in the string before the first space, where a reperesents the ending numeric value and 0 represents where the first letter begins.
   int b = record.indexOf(':',a);
   name2[cc] = record.substring(a,b);
   int c = record.indexOf(';',b);
   sex[cc] = record.substring(b+1,c);

   JOptionPane.showMessageDialog(null,name1[cc]);
   JOptionPane.showMessageDialog(null,name2[cc]);
   JOptionPane.showMessageDialog(null,sex[cc]);

   for (int aa=0;aa<5,aa++)
         {
      int d = record.indexOf(',',c+1);
      scores[cc][aa] = record.substring(c,d);

          }


        cc ++;


      }
          while ( cc <10);

I used the JOptionPanes to show me if I correctly stored them into their proper arrays, but I've tried everything for the integer array scores[][] but to this minute i'm still stumped on how to attack this problem. I've gone to Java Sun's website, my professor's website, and many others, but haven't found my answer yet.. Could you please give me a tad bit of a baby clue or some mothering on how I could recorde the 5 scores into the scores array; also, If I have something wrong with the for loop I've created in the do while loop let me know!! :) :). I don't know any other place other then this on where to refrence from for this matter...I hope this small problem can be eliminated!

Thank you!!
Jon

Oh by the way I use Borelands JBuilder University Issue, and also the SDK Enviornment.

Recommended Answers

All 2 Replies

try using a java.util.HashMap to store the scores like:

HashMap<String,Integer[]> scoresMap = new HashMap<String,Integer[]>();

...
Integer[] scores = {100,40,50,60,80};
scoresMap.put(name1+name2, scores);//name1+name2 is the key
...

Hello, I see that this is your first post. Please read the rules of the forums. This thread is 6 years old. The rules are found at the top of every forum.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.