Java要求设计一个“坐标点”类(Point)

.①包含X坐标和Y坐标值字段(都为int类型);②包含一个有参构造方法,该方法完成指定坐标的赋值;③包含一个无参构造方法,该方法指定为坐标原点值;④包含一个方法display方法用于显示以下信息“点:X= ;Y= ”。

public class Point {

double x1,x2,y1,y2;
double d,x3,y3;
Point(double x1,double y1,double x2,double y2){//构造方法
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
void TestPoint(){//求距离和中点坐标
x3 = (x1 + x2)/2;
y3 = (y1 + y2)/2;
d = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

System.out.println("(" + x3 + ","+ y3 + ")");
System.out.println(d);
}

public static void main(String[] args) {
Point p = new Point(1,1,2,2);
p.TestPoint();

}

}
温馨提示:内容为网友见解,仅供参考
无其他回答

java编写一个表示坐标点的类(Point),其中包含x和y两个坐标点的值,并且...
this.y = y; } public displayPoint (){ \/\/输出坐标 System.out.println("x:"+x+",y:"+y); } public static distancePoint(Point p1, Point p2){ \/\/计算坐标距离 int a = p1.getX()-p2.getX(); int b = p1.getY()-p2.getY(); return Math....

java定义一个点类(point),包含x,y坐标数据成员,显示函数(show)和计算...
Class Point{public int x;public int y;public Point(){}public void show(){}public int getarea(){}}Class Circle extends Point{public int r;public Circle(){}public int getarea(){return r*r;}}Class Line{public Point a=null;public Point b=null;public Line(int ax,int ay,int...

求高手用JAVA帮我设计一个完整的Point类,可以计算两点之间距离和中间...
public static void main(String[] args) { Point p = new Point(1,1,2,2);p.TestPoint();} } 如果还有其他要求的话,我再改进一下。

Java定义一个Point(点)类
public class Point { public static void main(String[] args){ Point p1=new Point();Point p2=new Point(1,2);p1.show();p1.move(3,4);p1.show();p2.show();p2.move(5,6);p2.show();} Point(){ this(0,0);} Point(float x,float y){ this.x=x;this.y=y;} void...

java编程 定义一个类Point,代表一个点,public属性有x和y,方法有显示点...
public class Test{ public static void main(String[] args){ MyPoint p1 = new MyPoint(); MyPoint p2 = new MyPoint(6.0,8.0); MyPoint p = MyPoint.getMiddle(p1,p2); System.out.print("点1:"); p1.show(); System.out.print("点2:"); p2.sh...

java 编程创建一个Point类
public Point() { this.x = 0;this.y = 0;} \/ 移动到点(dest1,dest2)param dest1 param dest2 \/ public void moveTo(float dest1, float dest2) { this.x = dest1;this.y = dest2;} public void printPoint() { System.out.print("当前点坐标:" + "(" + x + "," + y...

JAVA编程问题 定义一个泛型类Point,它包含横坐标x和纵坐标y两个变量...
public void outPut(Point<T> p){ System.out.println("点的x坐标为:"+p.getX());System.out.println("点的y坐标为:"+p.getY());} public static void main(String[] args) { Point<Integer> p=new Point<Integer>(1,2);p.outPut(p);Point<Double> d=new Point<Double>(1.0,2....

Java问题烦劳大家:定义一个点类(Point)
\/\/测试类 import java.util.Scanner;public class Test { public static void main(String[] args){ Scanner input = new Scanner(System.in);System.out.println("请输入一个点的X轴坐标:");double x=input.nextDouble();System.out.println("请输入一个点的y轴坐标:");double y=input....

java设计题:设计一个Point类,该类包含两个Int型成员变量:x,y,一个Co...
import java.awt.Color;public class Point { private int x;\/\/x坐标 private int y;\/\/y坐标 private Color color;\/\/颜色 public Point() {\/\/不带参数的构造方法 } public Point(int x,int y) {\/\/带两个参数的构造方法 this.x = x;this.y = y;} public Point(int x,int y,Color ...

定义一个Java类Point,用来描述平面直角坐标系中点的坐标。
Point.java 这个类近似于常说的工具类或者辅助类.这里面既然对坐标操作就应该定义全局的x,y变量.其他的就是 方法.public void setXY(double x,double y){ this.x = x;this.y = y;} set方法就是类似于这样,把传过来的值赋给定义的全局.而get方法里面很显然就是return.而测试类就是调用Point...

相似回答