سلام به همه
جواب ها در زیر آمده است:
package hw3; public class Path { int[] points_x; int[] points_y; int nPoints = 0; Path(){ points_x = new int[100]; points_y = new int[100]; } public Path addPoint(int x, int y){ Path newPath = new Path(); for (int i = 0; i < this.nPoints; i++) { newPath.points_x[i] = this.points_x[i]; newPath.points_y[i] = this.points_y[i]; } newPath.points_x[this.nPoints] = x; newPath.points_y[this.nPoints] = y; newPath.nPoints = this.nPoints + 1; return newPath; } public int getLength(){ return this.nPoints; } public void addPath(Path p){ for (int i = this.nPoints; i < this.nPoints+p.nPoints; i++) { this.points_x[i] = p.points_x[i-this.nPoints]; this.points_y[i] = p.points_y[i-this.nPoints]; this.nPoints++; } } public double getDistance(){ if (this.nPoints==1 || this.nPoints==0) return 0; double dist = 0; for (int i = 1; i < this.nPoints; i++) { dist+=Math.sqrt(Math.pow(this.points_x[i]-this.points_x[i-1],2)+Math.pow(this.points_y[i]-this.points_y[i-1],2)); } return dist; } boolean isLonger(Path p){ if(this.getLength() > p.getLength()) return true; else return false; } boolean removePoint(int n){ if (n >= this.nPoints) return false; else{ for (int i = n-1; i < this.nPoints; ++i){ this.points_x[i] = this.points_x[i+1]; this.points_y[i] = this.points_y[i+1]; } this.nPoints = -1; return true; } } }
برای کلاس Date به زودی به روزرسانی میشود.
- ۹۲/۰۸/۱۵