没明白isLargeThan是什么意思,能说得详细点儿么?
先把满足前四个条件的程序发给你,你看看行不行.
注:一个类一个java文件,运行Test3类执行.
public class Point {
\x05private double x;
\x05private double y;
\x05public Point() {
\x05\x05x=0;
\x05\x05y=0;
\x05}
\x05public Point(double x,double y){
\x05\x05this.x=x;
\x05\x05this.y=y;
\x05}
\x05public double getX(){
\x05\x05return this.x;
\x05}
\x05public double getY(){
\x05\x05return this.y;
\x05}
\x05public void setX(double x){
\x05\x05this.x=x;
\x05}
\x05public void setY(double y){
\x05\x05this.y=y;
\x05}
\x05public Point translate(double u,double v){
\x05\x05this.x=this.x+u;
\x05\x05this.y=this.y+v;
\x05\x05return new Point (this.x,this.y);
\x05}
}
public class Rectangle extends Point {
private double height;
private double wideth;
\x05public Rectangle() {
\x05\x05super();
\x05}
\x05public Rectangle(Point p,double h,double w){
\x05\x05super(p.getX(),p.getY());
\x05\x05this.height=h;
\x05\x05this.wideth=w;
\x05}
public double getPerimeter(){
\x05return 2*(height+wideth);
}
public double getArea(){
\x05return height*wideth;
}
}
public class Ellipse extends Point{
\x05 private double height;
\x05 private double wideth;
\x05\x05public Ellipse() {
\x05\x05\x05super();
\x05\x05}
\x05\x05public Ellipse(Point p,double h,double w){
\x05\x05\x05super(p.getX(),p.getY());
\x05\x05\x05this.height=h;
\x05\x05\x05this.wideth=w;
\x05\x05}
\x05 public double getPerimeter(){
\x05 \x05return 2*3.14*Math.sqrt((height*height+wideth*wideth)/2);
\x05 }
\x05 public double getArea(){
\x05 \x05return 3.14*height*wideth;
\x05 }
}
public class Test3 {
\x05public static void main(String[] args) {
\x05\x05Point p=new Point(1.2,4.6);
\x05\x05Rectangle r=new Rectangle(p,9.2,8.7);
\x05\x05Ellipse e=new Ellipse(p,3.2,9.2);
\x05\x05Point p1=p.translate(2.8,2.9);
\x05\x05
\x05\x05System.out.println("移动后的点为x="+p1.getX()+" y="+p1.getY());
\x05\x05
\x05\x05System.out.println("长方形的周长为:"+r.getPerimeter());
\x05\x05System.out.println("长方形的面积为:"+r.getArea());
\x05\x05System.out.println("椭圆形的周长为:"+e.getPerimeter());
\x05\x05System.out.println("椭圆形的面积为:"+e.getArea());
\x05}
}
作业帮用户
2016-12-02
举报