java中的一个MyPoint方法
设计一个Circle类,其属性为原点(类型为类MyPoint)和半径,并为此类编写以下三个方法:
一、计算圆的面积的calArea()方法;
二、计算周长的calLength()方法;
三、boolean inCircle(MyPoint mp)方法,功能是测试作为参数的某个点是否在当前对象圆内(圆内,包括圆上返回true,在圆外返回false)。
程序:
class MyPoint{
private int x,y;
public void setX(int x){
this.x=x;
}
public int getX(){
return this.x;
}
public void setY(int y){
this.y=y;
}
public int getY(){
return this.y;
}
public String toString(){
String str="("+this.x+","+this.y+")";
return str;
}
}
class Circle {
private MyPoint myPoint=null;
private double radius=0.0;
public Circle(MyPoint myPoint,int radius){
this.myPoint=myPoint;
this.radius=radius;
}
public double calArea(){
return Math.PI*radius*radius;
}
public double calLength(){
return 2*Math.PI*radius;
}
public boolean inCircle(MyPoint mp){
double a=Math.sqrt(Math.pow(mp.getX()-myPoint.getY(),2)+Math.pow(mp.getY()-myPoint.getY(),2));
if(a>radius){
return false;
}
return true;
}
}
public class T14{
public static void main(String args[]){
MyPoint mp=new MyPoint();
mp.setX(0);
mp.setY(0);
Circle c=new Circle(mp,5);
double area=c.calArea();
double length=c.calLength();
MyPoint mp2=new MyPoint();
mp2.setX(3);
mp2.setY(3);
boolean in=c.inCircle(mp2);
System.out.println("area="+area+",length="+length+",inCircle="+in);
}
}
测试结果:
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
public class ReadXML {
private File file;
public ReadXML(String filename){
File file=new File(filename);
this.file=file;
}
/**
......
java exception 解决方案 - 我的异常网|异常|exception 770 - java.net.unknownhostException 771 - com.ibatis.struts.BeanActionException 772 - javax.servlet.jsp.JspException:Cannot find bean under name org.apache.struts.taglib.html.BEAN 773 - java.lang.NoClassDefFoundError:org apache commons lang Unhand ......
3.package com.ncs.opts.tools;
import java.util.HashMap;
import java.util.Map;
import com.ncs.opts.common.icp.dao.po.audit.IcpMainHistory;
import com.ncs.opts.common.icp.dao.po.audit.IcpModifyHistory;
import com.ncs.opts.common.icp.dao.po.audit.IcpSiteAccessHistory;
import com.ncs.opts.common.i ......