试题五(共15分)阅读以下说明和Java程序,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下Java代码实现一个简单的聊天室系统(ChatRoomSystem),多个用户(User)可以向聊天室(ChatRoom)发送消息,聊天室将消息展示给所有用户。类图如图5-1所示。 【Java代码】classChatRoom{ publicstaticvoidshowMessage(Useruser,Strmgmessage){System.out.println("["+user.getName()+"]:"+message);}}classUser{privateStringname;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicUser(Stringname){(1)=name;}publicvoidsendMessage(Stringmessage){(2)(this,message);}}publicclassChat:RoomSystem{publicvoidstartup(){ Userzhang=newUser("John");Userli=newUser("Leo");zhang.sendMessage("Hi!Leo!");1i.sendMessage("Hi!John!");}publicvoidjoin(Useruser){(3)("HelloEveryone!Iam"+user.getName());}publicstaticvoidmain(String[]args){ChatRoomSystemcrs=(4);Crs.startup();Crs.join((5))(“Wayne”));}}/*程序运行结果:[John]:Hi!Leol[Leo]:Hi!John![Wayne】:HelloEveryone!IamWayne*/
1、this.name 2、ChatRoom.showMessage 3、user.sendMessage 4、new ChatRoomSystem() 5、new User