java编程:编Point类,有两属性x,y,一个方法distance(Point p1,Point p2),算两点距离
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 06:19:27
java编程:编Point类,有两属性x,y,一个方法distance(Point p1,Point p2),算两点距离,我用内部类做不
最好是用手动输入坐标点的
最好是用手动输入坐标点的
import java.util.Scanner;
public class Point {
private double x;
private double y;
public Point() {
this(0,0);
}
public Point(double x, double y){
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please input x for point 1:");
double x1 = scanner.nextDouble();
System.out.print("Please input y for point 1:");
double y1 = scanner.nextDouble();
System.out.print("Please input x for point 1:");
double x2 = scanner.nextDouble();
System.out.print("Please input y for point 1:");
double y2 = scanner.nextDouble();
double distance = Point.distance(new Point(x1, y1), new Point(x2, y2));
System.out.println("The distance is: " + distance);
}
public static double distance(Point p1, Point p2){
return Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY()-p2.getY(), 2));
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
---------------------
Please input x for point 1:0
Please input y for point 1:3
Please input x for point 1:4
Please input y for point 1:0
The distance is: 5.0
public class Point {
private double x;
private double y;
public Point() {
this(0,0);
}
public Point(double x, double y){
this.x = x;
this.y = y;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please input x for point 1:");
double x1 = scanner.nextDouble();
System.out.print("Please input y for point 1:");
double y1 = scanner.nextDouble();
System.out.print("Please input x for point 1:");
double x2 = scanner.nextDouble();
System.out.print("Please input y for point 1:");
double y2 = scanner.nextDouble();
double distance = Point.distance(new Point(x1, y1), new Point(x2, y2));
System.out.println("The distance is: " + distance);
}
public static double distance(Point p1, Point p2){
return Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY()-p2.getY(), 2));
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
---------------------
Please input x for point 1:0
Please input y for point 1:3
Please input x for point 1:4
Please input y for point 1:0
The distance is: 5.0
java编程:编Point类,有两属性x,y,一个方法distance(Point p1,Point p2),算两点距离
定义point累来描述平面上的点,包含私有数据成员x和y.定义友元函数distance计算两点距离(说明两点p1(x1,
定义一个Point类并用成员函数 double Distance(const& Point)求两点间距离
JAVA编程问题 定义一个泛型类Point,它包含横坐标x和纵坐标y两个变量,类型均为T
point
JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数
设计一个点类Point其属性为其x,y坐标,能计算该点到(0,0)的距离.
java问题..谢谢lass Point { double x,y,z; Point(double _x,double
类定义为什么要这样class point{public:double x,y;point(){};point(doubl
Java:定义父类Point,包含两个成员变量x,y和参数的构造方法,子类Point3D增加一个静态变量c用来统计主类中
4.可以定义点类(Point),再定义一个类(Distance)描述两点之间的距离,其数据成员为两个点类对象,两点
定义一个点类(Point),其数据成员包含横坐标和纵坐标;再定义一个距离类(Distance),用于描述两点之间