Problem with this. Help!

Hey guys, this is very important...

Any ANY help will be much appreciated

READ THE COMMENTS FOR DESCRIPTION WHAT SHOULD IT DO.

/*

Task Description:

I need to read from a text file, every uneven line number is a user and every even line number is a score. each of these arrays must be seperate. Array, users and scores. This array must be sorted using bubblesort.

Then printed into each ones own textarea, with a button to click to sort.

*/

//-

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.PrintStream;

/**/import javax.swing.filechooser.*;

import java.util.StringTokenizer;

import java.lang.Object;

/**/import javax.swing.*;//--

/**/import javax.swing.event.*;//--

/**/import java.io.File;//--

/**/import java.awt.*;//--

/**/import java.awt.event.*;//--

/**/import java.io.*;//--

//-

class Taak15March07extends JFrameimplements ActionListener

{

JButton button =new JButton ("Sort");

JTextArea textarea =new JTextArea (20, 10);

public Taak15March07 ()

{

super ("My Taak Vir IT");

setSize (1000, 500);

setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

setVisible (true);

Container content = getContentPane ();

FlowLayout layout =new FlowLayout ();

content.setLayout (layout);

button.addActionListener (this);

content.add (button);

content.add (textarea);

setContentPane (content);

}

publicvoid actionPerformed (ActionEvent event)

{

String str ="From: " + event.getActionCommand ();

if (event.getSource () == button)

str +=" - No. 1";

textarea.setText (str);

}

publicstaticvoid main (String [] args)throws Exception

{

Taak15March07 eg =new Taak15March07 ();

Taak15March07 f =new Taak15March07 ();

f.readMyFile ();

}

java.io.File cdlist =new java.io.File("mydata.txt");

FileReader infile =new FileReader(cdlist);

//FileWriter outfile = new FileWriter("newlist.txt");

BufferedReader br =new BufferedReader(infile);

//BufferedWriter out = new BufferedWriter(new FileWriter("newlist.txt"));

if (cdlist.exists()){

String [] textArray =new String[99];

String line;

int lineNum = 0;

while ((line = br.readLine()) !=null){

textArray[lineNum++] = line;

/*System.out.println*/textarea.setText(line);

}

int numOfCds = 1;

int boxNum = 1;

int boxPos = 1;

int cdsPerBox = 20;

out.write("Contents of Box " + boxNum);

out.newLine();

out.newLine();

for(int i = 0; i<textArray.length; i++){

out.write(textArray[i] +" box position: " + boxPos +"\n");

out.newLine();

boxPos++;

numOfCds++;

if (boxPos >= cdsPerBox){

boxNum++;

out.newLine();

out.newLine();

out.write("Contents of Box " + boxNum);

out.newLine();

out.newLine();

boxPos = 1;

}

}

infile.close();

out.close();

}else{

System.out.println("file not found, program terminating");

System.exit(0);

}

}

}

MYDATA.TXT CONTAINS:

jan

100

john

357

noob

3258

gudon

9999

netspike

9811

frogboy

135

seraphs

1

Any help from you java wizards will be appreciated!

[6662 byte] By [GuDoNa] at [2007-11-26 22:13:35]
# 1
What's your question?Do the sorting code for you ?
rym82a at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 2

So, it's very important? Running out of budget? Is the faith of the world depending on your taak?

> these arrays must be seperate. Array, users and scores

You describe that you need to split your data into 2 separate arrays. Where are they?

Change the while loop:

while (read odd line) {

write line to array users

read next (even line)

write line to array score

}

Peetzorea at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 3

this isn't for a company dude.

im just learning java, so telling me to just take every second line of the app would just confuse me.

String users[] = {?WHAT?};

String scores[] = {?WHAT?};

i know this is a lot to ask, but if you can just edit my code, and everytime add the source code to where it has to go. using the full source.

The arrays needs to be created. But it needs to contain every second line in mydata.txt

So i don't know how to do that, so i cannot put it into my source, otherwise the program wont work. Becuase i dont know what to do. aka ERROR.

GuDoNa at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 4

> this isn't for a company dude.

>

> im just learning java, so telling me to just take

> every second line of the app would just confuse me.

>

> > String users[] = {?WHAT?};

> String scores[] = {?WHAT?};

>

>

>

> i know this is a lot to ask, but if you can just edit

> my code, and everytime add the source code to where

> it has to go. using the full source.

>

> The arrays needs to be created. But it needs to

> contain every second line in mydata.txt

>

> So i don't know how to do that, so i cannot put it

> into my source, otherwise the program wont work.

> Becuase i dont know what to do. aka ERROR.

sorry, but "not knowing what to do" is not aka ERROR. "ERROR" would be "I've tried this piece of code, but it doesn't work properly"

georgemca at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 5
error is:BufferedReader br = new BufferedReader(infile);BufferedReader br = new BufferedReader(infile);{ expected after this token.I don't get it.
GuDoNa at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 6

The codejava.io.File cdlist = new java.io.File("mydata.txt");

FileReader infile = new FileReader(cdlist);

//FileWriter outfile = new FileWriter("newlist.txt");

BufferedReader br = new BufferedReader(infile);

is not inside a method!

prometheuzza at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 7
edit: double post
prometheuzza at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 8

> this isn't for a company dude

Oh, really? It looked like a large, time critical business application to me!

I'm not gonna write your code, you learn better by thinking about it yourself. Btw, are you mixing code of 2 different programs into one? You ask about users and scores and you do stuff with CD boxes... Maybe taking out those CD box statements gives you a clearer view of what you are doing. Let me make it a little more clear:

while (read next line from file) {

write the line you just read to array users

read next line from file

write the line you just read to array score

}

By reading twice in one loop you can avoid using an if statement.

Message was edited by:

Peetzore

Peetzorea at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 9
>By reading twice in one loop you can avoid> using an if statement.> True but if there will be odd numer of lines in a file, magick will happen. :)
hellbindera at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...
# 10
> True but if there will be odd numer of lines in a file, magick will happen. :) Is that where the world comes to an end?If he reads the line the way he does in the while loop test, no magick will happen! I only provided pseudo code, the rest was for the OP to fill in.
Peetzorea at 2007-7-10 11:04:01 > top of Java-index,Java Essentials,Java Programming...