2007年11月8日 星期四

第7題

import java.io.*;import java.util.*;import java.awt.geom.Point2D;

class 第7題 {
public static void main (String args[]) {
String thisLine;
for (int i=0; i < args.length; i++) {
try {FileInputStream fin = new FileInputStream(args[i]);
try {DataInputStream myInput = new DataInputStream(fin);
try {while ((thisLine = myInput.readLine()) != null) {StringTokenizer st = new StringTokenizer(thisLine, " ,");double p1n, p1e, p2n, p2e, p3n, p3e, p4n, p4e, p5n, p5e, sum;
p1n = Double.parseDouble(st.nextToken());System.out.println("第一點北緯UTM:" + p1n);p1e = Double.parseDouble(st.nextToken());System.out.println("第一點東經UTM:" + p1e);p2n = Double.parseDouble(st.nextToken());System.out.println("第二點北緯UTM:" + p2n);p2e = Double.parseDouble(st.nextToken());System.out.println("第二點東經UTM:" + p2e);p3n = Double.parseDouble(st.nextToken());System.out.println("第三點北緯UTM:" + p3n);p3e = Double.parseDouble(st.nextToken());System.out.println("第三點東經UTM:" + p3e);p4n = Double.parseDouble(st.nextToken());System.out.println("第四點北緯UTM:" + p4n);p4e = Double.parseDouble(st.nextToken());System.out.println("第四點東經UTM:" + p4e);p5n = Double.parseDouble(st.nextToken());System.out.println("第五點北緯UTM:" + p5n);p5e = Double.parseDouble(st.nextToken());System.out.println("第五點東經UTM:" + p5e);
Point2D.Double p1 = new Point2D.Double(p1n, p1e);Point2D.Double p2 = new Point2D.Double(p2n, p2e);Point2D.Double p3 = new Point2D.Double(p3n, p3e);Point2D.Double p4 = new Point2D.Double(p4n, p4e);Point2D.Double p5 = new Point2D.Double(p5n, p5e);
System.out.println("一英尺=0.3048公尺");System.out.println("P1到P2的距離: " + p1.distance(p2) + "公尺");System.out.println("P1到P2的距離: " + p1.distance(p2)/0.3048 + "英尺");System.out.println("P2到P3的距離: " + p2.distance(p3) + "公尺");System.out.println("P2到P3的距離: " + p2.distance(p3)/0.3048 + "英尺");System.out.println("P3到P4的距離: " + p3.distance(p4) + "公尺");System.out.println("P3到P4的距離: " + p3.distance(p4)/0.3048 + "英尺");System.out.println("P4到P5的距離: " + p4.distance(p5) + "公尺");System.out.println("P4到P5的距離: " + p4.distance(p5)/0.3048 + "英尺");
sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("五點距離總和: " + sum + "公尺");System.out.println("五點距離總和: " + sum/0.3048 + "英尺");
}
}catch (Exception e) {System.err.println("Error: " + e);}}catch (Exception e) {System.err.println("Error: " + e);}
}catch (Exception e) {System.err.println("failed to open file " + args[i]);System.err.println("Error: " + e);}}
}}

第6題

import java.io.*;import java.util.*;import java.awt.geom.Point2D;

class ComputeDatain {
public static void main (String args[]) {
String thisLine;
for (int i=0; i < args.length; i++) {
try {FileInputStream fin = new FileInputStream(args[i]);
try {DataInputStream myInput = new DataInputStream(fin);
try {while ((thisLine = myInput.readLine()) != null) {StringTokenizer st = new StringTokenizer(thisLine, " ,");double p1n, p1e, p2n, p2e, p3n, p3e, p4n, p4e, p5n, p5e, sum;
p1n = Double.parseDouble(st.nextToken());System.out.println("第一點北緯UTM:" + p1n);p1e = Double.parseDouble(st.nextToken());System.out.println("第一點東經UTM:" + p1e);p2n = Double.parseDouble(st.nextToken());System.out.println("第二點北緯UTM:" + p2n);p2e = Double.parseDouble(st.nextToken());System.out.println("第二點東經UTM:" + p2e);p3n = Double.parseDouble(st.nextToken());System.out.println("第三點北緯UTM:" + p3n);p3e = Double.parseDouble(st.nextToken());System.out.println("第三點東經UTM:" + p3e);p4n = Double.parseDouble(st.nextToken());System.out.println("第四點北緯UTM:" + p4n);p4e = Double.parseDouble(st.nextToken());System.out.println("第四點東經UTM:" + p4e);p5n = Double.parseDouble(st.nextToken());System.out.println("第五點北緯UTM:" + p5n);p5e = Double.parseDouble(st.nextToken());System.out.println("第五點東經UTM:" + p5e);
Point2D.Double p1 = new Point2D.Double(p1n, p1e);Point2D.Double p2 = new Point2D.Double(p2n, p2e);Point2D.Double p3 = new Point2D.Double(p3n, p3e);Point2D.Double p4 = new Point2D.Double(p4n, p4e);Point2D.Double p5 = new Point2D.Double(p5n, p5e);
System.out.println("P1到P2的距離: " + p1.distance(p2) + "公尺");System.out.println("P2到P3的距離: " + p2.distance(p3) + "公尺");System.out.println("P3到P4的距離: " + p3.distance(p4) + "公尺");System.out.println("P4到P5的距離: " + p4.distance(p5) + "公尺");
sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("五點距離總和: " + sum + "公尺");
}
}catch (Exception e) {System.err.println("Error: " + e);}}catch (Exception e) {System.err.println("Error: " + e);}
}catch (Exception e) {System.err.println("failed to open file " + args[i]);System.err.println("Error: " + e);}}
}}

第5題

import java.io.*;import java.awt.geom.Point2D;
public class 第5題 {public static void main(String[] args) throws IOException {BufferedReader keyin;keyin = new BufferedReader(new InputStreamReader(System.in));double p1n, p1e, p2n, p2e, p3n, p3e, p4n, p4e, p5n, p5e, sum;System.out.println("輸入第一點北緯UTM: ");String n1 = keyin.readLine();p1n = Double.parseDouble(n1);System.out.println("輸入第一點東經UTM: ");String e1 = keyin.readLine();p1e = Double.parseDouble(e1);System.out.println("輸入第二點北緯UTM: ");String n2 = keyin.readLine();p2n = Double.parseDouble(n2);System.out.println("輸入第二點東經UTM: ");String e2 = keyin.readLine();p2e = Double.parseDouble(e2);System.out.println("輸入第三點北緯UTM: ");String n3 = keyin.readLine();p3n = Double.parseDouble(n3);System.out.println("輸入第三點東經UTM: ");String e3 = keyin.readLine();p3e = Double.parseDouble(e3);System.out.println("輸入第四點北緯UTM: ");String n4 = keyin.readLine();p4n = Double.parseDouble(n4);System.out.println("輸入第四點東經UTM: ");String e4 = keyin.readLine();p4e = Double.parseDouble(e4);System.out.println("輸入第五點北緯UTM: ");String n5 = keyin.readLine();p5n = Double.parseDouble(n5);System.out.println("輸入第五點東經UTM: ");String e5 = keyin.readLine();p5e = Double.parseDouble(e5);
Point2D.Double p1 = new Point2D.Double(p1n, p1e);Point2D.Double p2 = new Point2D.Double(p2n, p2e);Point2D.Double p3 = new Point2D.Double(p3n, p3e);Point2D.Double p4 = new Point2D.Double(p4n, p4e);Point2D.Double p5 = new Point2D.Double(p5n, p5e);
System.out.println("P1到P2的距離: " + p1.distance(p2));System.out.println("P2到P3的距離: " + p2.distance(p3));System.out.println("P3到P4的距離: " + p3.distance(p4));System.out.println("P4到P5的距離: " + p4.distance(p5));sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("五點距離總和: " + sum);
}
}

第5題

import java.io.*;import java.awt.geom.Point2D;
public class 第5題 {public static void main(String[] args) throws IOException {BufferedReader keyin;keyin = new BufferedReader(new InputStreamReader(System.in));double p1n, p1e, p2n, p2e, p3n, p3e, p4n, p4e, p5n, p5e, sum;System.out.println("輸入第一點北緯UTM: ");String n1 = keyin.readLine();p1n = Double.parseDouble(n1);System.out.println("輸入第一點東經UTM: ");String e1 = keyin.readLine();p1e = Double.parseDouble(e1);System.out.println("輸入第二點北緯UTM: ");String n2 = keyin.readLine();p2n = Double.parseDouble(n2);System.out.println("輸入第二點東經UTM: ");String e2 = keyin.readLine();p2e = Double.parseDouble(e2);System.out.println("輸入第三點北緯UTM: ");String n3 = keyin.readLine();p3n = Double.parseDouble(n3);System.out.println("輸入第三點東經UTM: ");String e3 = keyin.readLine();p3e = Double.parseDouble(e3);System.out.println("輸入第四點北緯UTM: ");String n4 = keyin.readLine();p4n = Double.parseDouble(n4);System.out.println("輸入第四點東經UTM: ");String e4 = keyin.readLine();p4e = Double.parseDouble(e4);System.out.println("輸入第五點北緯UTM: ");String n5 = keyin.readLine();p5n = Double.parseDouble(n5);System.out.println("輸入第五點東經UTM: ");String e5 = keyin.readLine();p5e = Double.parseDouble(e5);
Point2D.Double p1 = new Point2D.Double(p1n, p1e);Point2D.Double p2 = new Point2D.Double(p2n, p2e);Point2D.Double p3 = new Point2D.Double(p3n, p3e);Point2D.Double p4 = new Point2D.Double(p4n, p4e);Point2D.Double p5 = new Point2D.Double(p5n, p5e);
System.out.println("P1到P2的距離: " + p1.distance(p2));System.out.println("P2到P3的距離: " + p2.distance(p3));System.out.println("P3到P4的距離: " + p3.distance(p4));System.out.println("P4到P5的距離: " + p4.distance(p5));sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("五點距離總和: " + sum);
}
}

第4題

import java.awt.geom.Point2D;
class ComputeDistance {
public static void main (String args[]) {double sum;Point2D.Double p1 = new Point2D.Double(371271.1364, 2781403.89);Point2D.Double p2 = new Point2D.Double(371306.8203, 2781500.173);Point2D.Double p3 = new Point2D.Double(371596.6543, 2781480.514);Point2D.Double p4 = new Point2D.Double(371578.2719, 2782009.544);Point2D.Double p5 = new Point2D.Double(371762.843, 2782147.181);
System.out.println("P1到P2的距離: " + p1.distance(p2));System.out.println("P2到P3的距離: " + p2.distance(p3));System.out.println("P3到P4的距離: " + p3.distance(p4));System.out.println("P4到P5的距離: " + p4.distance(p5));
sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("總距離為: " + sum);
}
}

期中第3題

import java.io.FileInputStream;import java.io.DataInputStream;import java.io.IOException;import java.io.PrintStream;import java.io.FileOutputStream;import java.io.IOException;
class StringFilelO {
public static void main (String args[]) {
String thisLine;
//Loop across the arguments for (int i=0; i < args.length; i++) {
//Open the file for reading try { FileInputStream fin = new FileInputStream(args[i]); FileOutputStream fout = new FileOutputStream("outdara.txt");
// now turn the FileInputStream into a DataInputStream try { DataInputStream myInput = new DataInputStream(fin); PrintStream myOutput = new PrintStream(fout);
try { while ((thisLine = myInput.readLine()) != null) { System.out.println(thisLine); myOutput.println(thisLine); } // while loop ends here } catch (Exception e) { System.err.println("Error: " + e); } } // end try catch (Exception e) { System.err.println("Error: " + e); }
} // end try catch (Exception e) { System.err.println("failed to open file " + args[i]); System.err.println("Error: " + e); } } // for end here
} // main ends here
}

2007年10月16日 星期二

作業心得

做了這些作業 我知道如何使用GEL這個軟體
可是裡面的內容還是完全不懂
只能照著老師的步驟 一步一步的慢慢跟著做