码迷,mamicode.com
首页 > 其他好文 > 详细

计算机17-3,4作业C

时间:2018-05-08 12:11:02      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:构造   enter   inter   double   变量   void   color   一个   boolean   

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 }

 

计算机17-3,4作业C

标签:构造   enter   inter   double   变量   void   color   一个   boolean   

原文地址:https://www.cnblogs.com/1Kasshole/p/9007261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!