ExtendsDemo

import java.*;
class Points
{
private int x;
private int y;
Points() //没有参数的构造器
{
x=0;
y=0;
}
Points(int x,int y)//有两个参数的构造器
{
this.x=x;
this.y=y;
}
Points(int x)//有一个参数的构造器
{
this.x=this.y=x;
}
public Points show()//输出
{
System.out.println(“X=”+x+
+”Y=”+y);
return this;
}
public Points change(int x,int y)//移动
{
this.x=x;
this.y=y;
return this;
}
public int getx()
{
return this.x;
}
public int gety()
{
return this.y;
}
}
class Shapes
{
public void show(){}
public void change(){}
}
class Circles extends Shapes
{
private Points center;//圆心
private int radius;//半径
public Circles(Points c,int r)//圆形的构造器
{
center=c;
radius=r;
}
public void show()//圆形的输出
{
System.out.println(“圆心坐标:”);
center.show();
System.out.println(“半径:R=”+this.radius);
}
public void change(Points p)//圆形的修改,改变圆心
{
center.change(p.getx(),p.gety());
}
public void change(Points p,int r)//圆形的修改,改变圆心和半径
{
this.change(p);
this.radius=r;
}
}
class Rectangles extends Shapes
{
private Points lt;
private Points lb;
private Points rt;
private Points rb;//定义左上,右下两个定点
private int length,width;
public Rectangles(Points lt,Points rb)//矩形的构造器,用两点构造
{
this.lt=new Points(lt.getx(),lt.gety());//左上角的点
this.rb=new Points(rb.getx(),rb.gety());//右下角的点
this.length=rb.getx()-lt.getx();//长
this.width=lt.gety()-rb.gety();//宽
this.lb=new Points(lt.getx(),lt.gety()-this.width);//左下角顶点=左上角-宽
this.rt=new Points(rb.getx(),rb.gety()+this.width);//右上角顶点=右下角+宽
}
public void show()
{
System.out.println(“四个角顶点坐标:”);
System.out.println(“左上角”);
this.lt.show();
System.out.println(“左下角”);
this.lb.show();
System.out.println(“右上角”);
this.rt.show();
System.out.println(“右下角”);
this.rb.show();
System.out.println(“长:length=”+length+”宽:width”+width);
}
public void change(Points lt,Points rb)
{
this.lt.change(lt.getx(),lt.gety());//左上角的点
this.rb.change(rb.getx(),rb.gety());//右下角的点
this.length=rb.getx()-lt.getx();//长
this.width=lt.gety()-rb.gety();//宽
this.lb.change(lt.getx(),(lt.gety()-this.width));//左下角顶点=左上角-宽
this.rt.change(rb.getx(),(rb.gety()+this.width));//右上角顶点=右下角+宽
}
}
class Doppelganger
{
public void commit()
{
System.out.println(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
System.out.println(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
System.out.println(“@@ @@”);
System.out.println(“@@ Doppelganger–孙博荣誉出品 @@”);
System.out.println(“@@ @@”);
System.out.println(“@@ 学号:012004021501 @@”);
System.out.println(“@@ @@”);
System.out.println(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
System.out.println(“@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@”);
}
}
public class ExtendsDemo//测试类
{
public static void main(String args[])
{
///////////////////////////////////////////////////////////////////////
//对Points的测试
System.out.println(“*************************************************”);
//用无参数方法构造Points
System.out.println(“构造一个点mypoint0:无输入参数”);
Points mypoint0=new Points();
System.out.println(“输出点:”);
mypoint0.show();
System.out.println(“”);

//用横纵坐标构造Points
System.out.println(“构造一个点mypoint1:输入两个参数Points(20,1)”);
Points mypoint1=new Points(1,20);
System.out.println(“输出点:”);
mypoint1.show();
System.out.println(“”);

//用一个参数构造横纵坐标向等的Points
System.out.println(“构造一个点mypoint2:输入一个参数Points(5)”);
Points mypoint2=new Points(5);
System.out.println(“输出点:”);
mypoint2.show();
System.out.println(“”);

//修改点的坐标
System.out.println(“修改点mypoint0,mypoint0.change(10,-1″);
System.out.println(“修改前:”);
mypoint0.show();
mypoint0.change(10,-1);
System.out.println(“修改后:”);
mypoint0.show();
System.out.println(“”);

///////////////////////////////////////////////////////////////////////
//对Circles的测试
System.out.println(“*************************************************”);
//构造一个Circles对象
System.out.println(“构造一个圆形mycircle输入参数为Circles(mypoint0,10)”);
Circles mycircle=new Circles(mypoint0,10);
System.out.println(“输出圆形:”);
mycircle.show();
System.out.println(“”);

//只改变圆心的位置
System.out.println(“改变mycircle圆心,mycircle.change(mypoint1)”);
mycircle.change(mypoint1);
System.out.println(“输出圆形:”);
mycircle.show();
System.out.println(“”);

//改变圆心和半径
System.out.println(“改变mycircle圆心和半径,mycircle.change(mypoint2,123)”);
mycircle.change(mypoint2,123);
System.out.println(“输出圆形:”);
mycircle.show();
System.out.println(“”);

////////////////////////////////////////////////////////////////////////
//对Rectengles的测试
System.out.println(“*************************************************”);
//构造一个Rectengles对象
System.out.println(“构造一个矩形myrectengle,参数为Rectangles(mypoint1,mypoint2)”);
Rectangles myrectengle=new Rectangles(mypoint1,mypoint2);
System.out.println(“输出矩形:”);
myrectengle.show();
System.out.println(“”);

////改变矩形位置
System.out.println(“改变矩形myrectengle对角两点,myrectengle.change(mypoint2,new Points(10,0))”);
myrectengle.change(mypoint2,new Points(10,0));
System.out.println(“输出矩形:”);
myrectengle.show();
System.out.println(“”);

////////////////////////////////////////////////////////////////////////
//测试结束
Doppelganger I=new Doppelganger();
I.commit();
System.out.println(“*************************************************”);
}
}

2 Responses

  1. Great Post…

    I saw this very informative post here, thank you…

  2. Product Reviews 说道:

    %BLOGTITLE%…

    I saw this wonderful post here at %BLOGTITLE%…

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word