Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you rewrite this method without using LinkedList?
#3
Why do you want to use anything else other than LinkedList? LinkedList makes sorting easier. Other than LinkedList you can use object arrays. But in arrays its difficult to add objects between two existing objects. Anyway, here's what you want:

Assuming that People() is pointing to a class constructor, the following code can be used.

People Class:

public class People {

public People(String name, char sex, double height, double weight, int number) {

//Your method code here

}
}


----------------------------------------------------------------------

ObjectList Class:

import java.io.*;

public class ObjectList {

static Object objList[];
private static Object[] create(String nameFile) {

try {

FileReader fi = new FileReader(nameFile);
BufferedReader enter = new BufferedReader(fi);

int varCounter = 0;

String aLine = enter.readLine();

while(aLine instanceof String) {

String name = aLine.substring(0, 10);
char sex = aLine.charAt(30);
double height = Double.parseDouble(aLine.substring(37, 41));
double weight = Double.parseDouble(aLine.substring(51, 56).trim());
int number = Integer.parseInt(aLine.substring(64));

objList[varCounter] = (new People(name, sex, height, weight, number));
varCounter++;

aLine = enter.readLine();
}

enter.close();
}

catch(Exception error) {
System.out.println("Error: "+error.toString());
}

return objList;
}
}


Did not use code tags as the text inside it is unreadable.
Reply


Messages In This Thread
RE: Can you rewrite this method without using LinkedList? - by aHardyX - 03-14-2012, 11:13 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)