Java程序设计作业3

Java程序设计作业3


2024年6月18日发(作者:)

《Java程序设计》作业三

教师:李家琦

学生:2013级本科、电子13001-13004班

13.7

设计一个名为Colorable的接口,其中有名为howToColor()的void方法。可着色

对象的每个类必须实现Colorable接口。设计一个扩展GeometricObject类并实现Colo

rable接口的名为Square的类。实现howToColor方法,显示消息“Colorall four side

s”。

画出包括Colorable、Square和GeometricObject的UML图。编写一个测试程序,

创建有五个GeometricObject对象的数组。对于数组中的每个对象而言,如果对象是可着

色的,那就调用howToColor方法。

Colorable接口

public interface Colorable {

void howToColor();

}

GeometricObject类

public class GeometricObject{

}

Square类

public class Square extends GeometricObject implements Colorable{

public void howToColor() {

n("Colorall four sides");

}

}

场景类Main

public class Main {

public static void main(String args[]){

GeometricObject[] gs = {new GeometricObject(),new GeometricObject(),n

ew Square(),new GeometricObject(),new GeometricObject(),};

for (GeometricObject geometricObject : gs) {


发布者:admin,转转请注明出处:http://www.yc00.com/news/1718698167a2751922.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信