62,623
社区成员
发帖
与我相关
我的任务
分享public class Point {
private int x;
private int y;
public Point() {
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}public class Line extends Point {
private Point p1;
private Point p2;
private int w;
public Line(Point p1, Point p2) {
this.p1 = p1;
this.p2 = p2;
}
public void move() {
int length = Math.abs(this.p1.getX() - this.p2.getX());
int height = Math.abs(this.p1.getY() - this.p2.getY());
w = (int) Math.sqrt((length * length + height * height));
}
public void print() {
System.out.println("Point 1 is : x=" + this.p1.getX() + ",y="
+ this.p1.getY());
System.out.println("Point 2 is : x=" + this.p2.getX() + ",y="
+ this.p2.getY());
System.out.println("The line width is " + w);
}
public static void main(String[] args) {
Point p1 = new Point(0, 0);
Point p2 = new Point(3, 4);
Line l = new Line(p1, p2);
l.move();
l.print();
}
}
import java.Math.*;
public class Line extends Point
{
Point point1;
Point point2;
int w;
public void move( Point point1, Point point2 )
{
w = Math.sqrt( ( point1.x - point2.x ) ^2 + ( point1.y - point2.y ) ^2)
}
public void printPara()
{
System.out.println( "Point 1: (" + point1.x + ", " + point1.y + ")");
System.out.println( "Point 2: (" + point2.x + ", " + point2.y + ")");
System.out.println( "width: " + w );
}
}
//Point.java
public class Point {
int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
//Line.java
public class Line extends Point {
int x1, y1, w;
public Line(int startX, int startY, int endX, int endY, int width) {
super(startX, startY);
x1 = endX;
y1 = endY;
w = width;
}
public void move(int newStartX, int newStartY, int newEndX, int newEndY) {
x = newStartX;
y = newStartY;
x1 = newEndX;
y1 = newEndY;
}
public void print() {
System.out.println("Line: x=" + x + "; y=" + y + "; x1="+ x1 +"; y1=" + y1 + "; w=" + w);
}
}
// Point类定义同上
// Line.java
public class Line {
Point start, end;
int w;
public Line(int startX, int startY, int endX, int endY, int width) {
start = new Point(startX, startY);
end = new Point(endX, endY);
w = width;
}
public void move(int newStartX, int newStartY, int newEndX, int newEndY) {
start = new Point(newStartX, newStartY);
end = new Point(newEndX, newEndY);
}
public void print() {
System.out.println("Line: start from (" + start.x+ "," + start.y + "), end at (" + end.x+ "," + end.y + "), width: " + w);
}
}
//Point.java
public class Point {
int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
//Line.java
public class Line extends Point {
int x1, y1, w;
public Line(int startX, int startY, int endX, int endY, int width) {
super(startX, startY);
x1 = endX;
y1 = endY;
w = width;
}
public void move(int newStartX, int newStartY, int newEndX, int newEndY) {
x = newStartX;
y = newStartY;
x1 = newEndX;
y1 = newEndY;
}
public void print() {
System.out.println("Line: x=" + x + "; y=" + y + "; x1="+ x1 +"; y1=" + y1 + "; w=" + w);
}
}
// Point类定义同上
// Line.java
public class Line {
Point start, end;
int w;
public Line(int startX, int startY, int endX, int endY, int width) {
start = new Point(startX, startY);
end = new Point(endX, endY);
w = width;
}
public void move(int newStartX, int newStartY, int newEndX, int newEndY) {
start = new Point(newStartX, newStartY);
end = new Point(newEndX, newEndY);
}
public void print() {
System.out.println("Line: start from (" + start.x+ "," + start.y + "), end at (" + end.x+ "," + end.y + "), width: " + w);
}
}