早教吧 育儿知识 作业答案 考试题库 百科 知识分享

各位计算机大神,求解java题目。1.编写Point类,描述平面坐标XY上的点。doublex,yPoint()Point(doublex,doubley)setPoint(doublex,doubley)getPointX()getPointY()----------------------------------------------编写Circ

题目详情
各位计算机大神,求解java题目。
1.编写Point类,描述平面坐标XY上的点。
double x,y

Point()
Point(double x,double y)

setPoint(double x,double y)
getPointX()
getPointY()
----------------------------------------------
编写Circle类,继承上述的Point类,描述平面坐标XY上的园。
double r

Circle()
Circle(Point p,double r)

setR(double r)
getCircumference()
getCircArea()
---------------------------------------------
编写主类TestCircle,计算园的周长和面积,并输出结果和圆心位置。
---------------------------------------------
2.定义抽象类Function,其中包含抽象方法doFunction()。
定义类Function11,描述一元一次方程,并重写抽象方法doFunction()。
定义类Function12,描述一元二次方程,并重写抽象方法doFunction()。
定义类Function21,描述二元一次方程,并重写抽象方法doFunction()。
--------------------------------------------------
编写主类TestFunction,求解上述三种方程,并输出结果。
------------------------------------------------------
3.将上述抽象类定义成接口,并完成同样的功能。
▼优质解答
答案和解析
package Circle;
/**
* 定义点类
* @author Sontion
*
*/
public class Point {
//X坐标和y坐标
private double x;
private double y;

//重写构造方法
public Point(double x, double y) {
this.x = x;
this.y = y;
}

//定义get/set方法
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;
}


}
package Circle;
/**
* 编写圆类
* @author Sontion
*
*/
public class Circle {
private double r;
private Point point;


public Circle(double r, Point point) {
super();
this.r = r;
this.point = point;
}


/**周长*/
public double getLength(Circle c){
double length=0.0;
double pi=3.14;

length=2*pi*c.getR();

return length;
}

/**面积*/
public double getArea (Circle c){
double length=0.0;
double pi=3.14;

length=pi*c.getR()*c.getR();

return length;
}



public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}




}
package Circle;
public class test {
public static void main(String[] args) {
Point po = new Point(1.0,1.0);
Circle c = new Circle(4.0,po);
double a = c.getLength(c);
double b = c.getArea(c);
System.out.println(a+","+b);
}
}
写了个,可能我没明白你的意思,算周长用x,y干嘛?