不知道这里应该怎样改了。怎么写都差一点。import java.util.*;
public class Assignment3 {
public static void main (String[] args) {
ArrayList lists;
lists = constructLists(\\"a3q1.txt\\");
}
//构造ArrayList
public static ArrayList constructLists(String filename) {
BufferedReader in;
ArrayList lists_temp = new ArrayList();
String line1,line2,line3;
try {
in = new BufferedReader(new FileReader(filename));
line1 = in.readLine();
while (line1 != null) {
line2 = in.readLine();
line3 = in.readLine();
lists_temp.add(new (list)list(line1,line2,line3));
line1 = readLine();
}
} catch (IOException ioe) {
System.out.println(getMessage());
ioe.printStackTrace();
}
return lists_temp;
}
class list {
public double double_val;
public Point p;
public String text;
public list(String s1,String s2, String s3) {
this.double_val = Double.parseDouble(s1);
this.p = new Point(s2);
this.text = s3;
//不知道这里是不是要写:
//return list;
}
public String toString() {
//输出List
}
}
//point (x,y)
class Point {
private double x,y;
public Point(double a,double b) {
this.x = a;
this.y = b;
}
public Point(String str) {
String s;
String[] tokens;
s = str.replaceAll(\\"(\\",\\"\\");
s = str.replaceAll(\\")\\",\\"\\");
tokens = line.split(\\",\\");
//用token来获取point(double a, double b)的a 和 b
this.x = Double.parseDouble(tokens[0]);
this.y = Double.parseDouble(tokens[1]);
}
public String toString() {
return \\"( \\" + x + \\", \\" + y + \\" )\\";
}
}
}
[ 本帖最后由 火星叔叔 于 2007-10-29 10:29 编辑 ] |