我很難完成爲學校完成此作業。除了標題中還有更多內容,但基本上這是我首先需要做的。閱讀具有x和y點的文本文件的每一行,提取它們,並將它們存儲在新節點中。然後,我需要將這個新節點添加到鏈接列表中,併爲每個xy座標重複。沒有數組將被使用。在LinkedList中存儲節點中的X,Y邊界座標
這是我到目前爲止的代碼:
public class Point {
public int data;
public Point next;
public Point(int data, Point next) {
this.data = data;
this.next = next;
}
@Override
public String toString() {
return data + "";
}
}
public class ShapeAbstraction {
public void readCoordinates() {
String fileName = "shapelist.txt";
String line = null;
try {
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println("Unable to open file " + fileName);
}
catch(IOException ex) {
System.out.println("Error reading file" + fileName);
}
}
public static void main(String[] args) {
ShapeAbstraction sa = new ShapeAbstraction();
sa.readCoordinates();
Point front = new Point(0, null);
System.out.println(front);
}
}
在.txt文件的座標這個樣子
10 0
18 0
17 2
21 7
19 12
這只是第5出幾百。
如果有人可以幫助,那將是驚人的。謝謝。 Assignment for reference順便說一下,我們現在允許使用java鏈接列表類。
謝謝,這有助於很多。我忘了提及,我們不需要再實現我們自己的鏈表方法。我們現在可以使用java鏈接列表類。 –