计算机17-3,4作业C

C.Class Degisn

Description
定义一个Circle类,有成员变量(或称之为域)x,y(圆心坐标)r(圆半径),成员方法intersect()两个圆是否相交的判断方法,和所需要的若干个构造方法。
Input
两个Circle类的成员变量值
Output
若交叉输出intersected,否则输出not intersected
Sample Input

10

10

5

60

60

5

 1 import java.util.*;
 2 public class Main{
 3     public static void main(String[] args){
 4         Scanner in = new Scanner(System.in);
 5         double x1,y1,r1,x2,y2,r2;
 6         x1 = in.nextDouble(); y1 = in.nextDouble(); r1 = in.nextDouble();
 7         x2 = in.nextDouble(); y2 = in.nextDouble(); r2 = in.nextDouble();
 8         Circle c1 = new Circle(x1,y1,r1);
 9         Circle c2 = new Circle(x2,y2,r2);
10         if(c1.intersect(c2))
11             System.out.println("intersected");
12         else
13             System.out.println("not intersected");
14     }
15 }
16 
17 class Circle{
18     private double x;
19     private double y;
20     private double radium;
21     public Circle(double x,double y,double radium){
22         this.x=x; this.y=y; this.radium=radium;
23     }
24     public boolean intersect(Circle c){
25         double dis = Math.sqrt((c.x-x)*(c.x-x)+(c.y-y)*(c.y-y));
26         return dis <= radium + c.radium;
27     }
28 }

猜你喜欢

转载自www.cnblogs.com/1Kasshole/p/9007261.html