求j**a代码

时间:2014.12.23 发布人:aoeiwuyu

求j**a代码

已解决问题

谷歌aoeiwuyu用户在2014.12.23提交了关于“优酷求j**a代码”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2025-03-02T09:07:08。

1.任选现实生活中的一件或多件有关联的实体,按照面向对象程序设计思想完成一级抽象,在一级抽象的基础上进行二次抽象,**生对应的类及子类;
2.体现出类的继承关系,在继承湿有覆盖,子类应具有父类特性,但要体现出与父类的差异,体现j**a语言的多态性;
3.主类中完成对象的设计,体现出不同对象之间的关系,有消息传递机制。
4.代码不少于100行。
5.写出设计说明及运行过程说明,代码至少2/3加注释。


希望大家能够帮助她。

详细问题描述及疑问:

1.任选现实生活中的一件或多件有关联的实体,按照面向对象程序设计思想完成一级抽象,在一级抽象的基础上进行二次抽象,**生对应的类及子类;
2.体现出类的继承关系,在继承湿有覆盖,子类应具有父类特性,但要体现出与父类的差异,体现j**a语言的多态性;
3.主类中完成对象的设计,体现出不同对象之间的关系,有消息传递机制。
4.代码不少于100行。
5.写出设计说明及运行过程说明,代码至少2/3加注释。


期待您的答案,我不知道说什么才好,除了谢谢 !
希望以下的回答,能够帮助你。

第1个回答

用户名:小头爸爸007  

/**
*
*@authorasus
*/
classShape{//描述抽象的形状
prote问答ctedintdegree;//边框厚度
prote肥具ctedintcolor程别;//边框颜色
public斯练啊宗吸款讲有Shape(){//默认构造方法
degree=1;
color神反行乱约独=1;//假设1表示红色,2表示绿色3表示蓝色
}
publicShape(intdegree,intcolor){//构造方法,初始化边框厚度和颜色
***.degree=degree;
t令必坏his.color=岁演讲比此句老重期头color;
}
publicdoublearea(){//返办走牛顺点粮合际关回面积,0
r造住黄呀均eturn0;
}

publicvoidDraw(){//绘制形状,给出默认形状
System.out.println("画出任意形状,边框["+
degree+"]颜色["+
color+"]");
}
}

classCirclee蛋致血预xtendsShape{//定义圆形
priva雨电娘历限tedoublera委空攻补复dius;//半径

publicCircle(doubleradius){//构造方法,初始化半径,边框厚度和颜色使用默认值
super();
this.radius=radi照us;
}
publicCircle(intdegree,intcolor,doubleradius){//构造方法,初始化半径,边框厚度和颜色使用传入值
super(degree,color);
this.radius=radius;
}
publicdoublearea(){//返回圆形面积
return3.14*radius*radius;
}
publicvoidDraw(){//绘制圆形
System.out值了卷磁者目.println("画出圆形,边框["+
degree认责+"]颜色["+
color+"]半径"+
radius+
"]");
}
}

classRectangleextendsS风台怎hape{//定义矩形
privatedo货远波怀果反ublelength;//长度
privatedoublewidth;//宽度

publicRectangle(doublelength,d留等研坐资散oublewidth){//构造方法,初始化长坚哥影马宽,边框厚度和颜色使用默认值
super();
this.length=length;
this.width=width;
}
publicRectangle(intdegree,intcolor,doublelength,doublewidth){//构造方法,初始化长宽,边框厚度和颜色使用传入值
super(degree,color);
this.length=length;
this.width=width;
}

publicdoublearea(){//返回矩形面积
returnlength*width;
}
publicvoidDraw(){//绘制矩形
System.out.println("画出矩形,边框["+
degree+"]颜色["+
color+
"]长度"+length+
"]宽度"+width+
"]");
}
}
publicclassMainClass{//主类
privateShapeshape;//形状,父类对象可以代表子类对象
publicMainClass(Shapeshape){//构造方法,初始化形状对象
this.shape=shape;
}
publicvoidsetShape(Shapeshape){//重置形状对象
this.shape=shape;
}
publicdoublegetAreaOfShape(){//获取面积
returnshape.area();
}
publicvoidDrawShape(){//绘制形状
shape.Draw();
}
publicstaticvoidmain(Stringargs[]){//主方法

Shapeshape;//定义一个形状引用
shape=newCircle(5.0);//构造一个圆形
MainClasstest=newMainClass(shape);//构造主类,并用shape初始化
test.DrawShape();//绘制形状
System.out.println("areaofshapeis"+test.getAreaOfShape());


shape=newRectangle(2,2,5.0,5.0);//构造一个矩形,边框厚度和颜色使用自定义值
test.setShape(shape);//用矩形设置形状
test.DrawShape();//绘制形状
System.out.println("areaofshapeis"+test.getAreaOfShape());
}
}