希望能尽量完整确实学不懂了TVT
1、我想要达到的结果
定义一个圆类用来表示二维空间中的一个圆,包括了圆心坐标和半径
可以生成一个具体的圆,写出构造函数
可以分别提供设置圆心坐标和半径的方法
提供一个判断空间一个点在圆内还是圆上,还是圆外的方法
实例化一个坐标为4,5,半径为6的圆,计算点(9,9)点是否在圆上
2、问题遇到的现象和发生背景
在站里只找到了怎么建立圆类的,比划着写了一点点但是后面就不会了
4、 我的解答思路和尝试过的方法
试着创建了圆类,但是不知道该怎么生成构造函数什么的,书上也没有
java编写,定义一个圆类用来表示二维空间中的一个圆,包括了圆心坐标和半径
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
溪风沐雪 2022-04-20 17:55关注给个例子,你参考一下吧:
class Point { private double x; private double y; public Point(double x, double y){ this.x = x; this.y = y; } public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; } } public class Circle{ private double radius; private Point center; public Circle(double radius, Point center){ this.radius = radius; this.center = center; } public void caclPosition(Point p){ double dist = Math.sqrt(Math.pow(p.getX()-this.center.getX(), 2)+Math.pow(p.getY()-this.center.getY(), 2)); if(dist==this.radius){ System.out.println("点p在圆上"); }else if(dist<this.radius){ System.out.println("点p在圆内"); }else{ System.out.println("点p在圆外"); } } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public Point getCenter() { return center; } public void setCenter(Point center) { this.center = center; } public static void main(String[] args) { Point center = new Point(4,5); Circle c = new Circle(6, center); Point p = new Point(9,9); c.caclPosition(p); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 2无用