hzbn.net
当前位置:首页>>关于求大神帮忙写一下程序,用java写 定义一个Point类...的资料>>

求大神帮忙写一下程序,用java写 定义一个Point类...

public class Point {private double x;private double y;// 获取距离public double getDistance(Point p) {return Math.sqrt(Math.pow(x - p.x, 2) + Math.pow(y - p.y, 2));}// 测试public static void main(String[] args) {Point p1 = new P...

public class Point{private double x;private double y;Point(){}Point(double a,double b){this.x=a;this.y=b;}public double getX(){return this.x;}public double getY(){return this.y;}public void setX(double a){this.x=a;}public void ...

public class Point { private int x; private int y; 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(...

public class twopoint {private int x;private int y;public void set(int a,int b){x = a;y = b;}public void get(){System.out.println("(" + x + "," + y + ")");}public twopoint(int c,int d){set(c,d);get();}}

实现思路就是有一个类Point,之后这个类有两个私有成员变量,之后可以通过set和get方法进行赋值和数值读取: public class Point { private String x; private String y; /** * 默认构造函数 */ public Point(){ } /** *有x和y的构造方法。 */ p...

class Point{ public Point(int x,int y) { this.x = x; this.y = y; } private int x; private int y; public float compute(Point p) { return Math.sqrt((p.x-this.x)^2-(p.y-this.y)^2); } } 距离 = new Point(3,4).compute(new Point(6,8))...

代码就不给你打了,我给你说思路,其实是很简单的。 需要两个类,一个Point,一个Test。这两个类,是调用和被调用的关系,Point被Test调用。 关系说好了,就是类具体实现的问题。 Point.java 这个类近似于常说的工具类或者辅助类。这里面既然对...

public class Point implements Cloneable { private int x; private int y; // 不带参数的构造方法 public Point() { this(0, 0); } // 带参数的构造方法 public Point(int x, int y) { this.x = x; this.y = y; } // 拷贝方法 @Override prote...

class Point{ private int point; public Point(int point) { super(); this.point = point; } public int getPoint() { return point; } public void setPoint(int point) { this.point = point; } }

public class Point {public double x;public double y;public Point(double x, double y) {this.x = x;this.y = y;}public double distance(Point pt) {double px = pt.x - this.x;double py = pt.y - this.y;return Math.sqrt(px * px + py * ...

网站首页 | 网站地图
All rights reserved Powered by www.hzbn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com