题目详情

阅读以下说明和Java程序,填补代码中空缺,将解答填入答题纸对应栏内。

[说明]

对部分乐器进行建模,其类图如下图所示,包括:乐器(Instrument)、管乐器(Wind)、打击乐器(Percussion)、弦乐器(Stringed)、木管乐器(Woodwind)、铜管乐器(Brass)。

初级程序员,章节练习,基础复习,初级程序员练习

类图

下面是实现上述设计Java代码,其中音乐类(Music)使用各类乐器(Instrument)进行演奏和调音等操作。

[Java代码] enum Note{/*枚举各种音调*/ MIDDLE_C,C_SHARP,B_FLAT; //其他略 } interfaceInstrument {/*接口,乐器*/ ______; //play方法接口 void adjust(); //adjust方法接口 } class Wind ______{ public voidplay(Note n) { System.out.println("Wind.play()"+n); } public void adjust(){System.out.println("Wind.adjust()");} } /*类Percussion和Stringed实现代码略*/ class Brass ______{ public voidplay(Note n) {System.out.println("Brass.play()"+n); } public voidadjust(){System.out.println("BrasS.adjust()");) } Class Woodwindextends Wind{ publicvoidplay(Note n){System.out.println("Woodwind.play()"+n); } } public classMusic{ voidtune(Instrument_i){i.play(Note.MIDDLE_C.; } voidadjust(Instrument i){i.adjust(); } voidtuneAll(______ e){ for(Instrumenti:e){ adjust(i); tune(i); } } public Static voidmain(String[] args){ Music music=______ Music(); Instrument[]orchestra={new Wind(), new Woodwind() }; music.tuneAll(orchestra); } }

本程序运行后输出结果为:

Wind.adjust() Wind.play()MIDDLE_C Wind.adjust() Woodwind.play()MIDDLE_C

正确答案及解析

正确答案
解析

voidplay (Note n)

implements Instrument

extends Wind

Instrument[]

new

你可能感兴趣的试题

单选题

高级系统分析师,专项练习,软件水平考试《高级系统分析师》押题

  • A.V(S2)和P(S4)
  • B.P(S2)和V(S4)
  • C.P(S2)和P(S4)
  • D.V(S2)和V(S4)
查看答案
单选题

高级系统分析师,专项练习,软件水平考试《高级系统分析师》押题

  • A.V(S1)P(S2)和V(S3)
  • B.P(S1)V(S2)和V(S3)
  • C.V(S1)V(S2)和V(S3)
  • D.P(S1)P(S2)和V(S3)
查看答案
单选题

高级系统分析师,专项练习,软件水平考试《高级系统分析师》押题

  • A.P(S4)和V(S4)V(S5)
  • B.V(S5)和P(S4)P(S5)
  • C.V(S3)和V(S4)V(S5)
  • D.P(S3)和P(S4)V(P5)
查看答案
单选题

高级系统分析师,专项练习,软件水平考试《高级系统分析师》押题

  • A.P(S3)和V(S4)V(S5)
  • B.V(S3)和P(S4)P(S5)
  • C.P(S3)和P(S4)P(S5)
  • D.V(S3)和V(S4)V(S5)
查看答案
单选题

高级系统分析师,专项练习,软件水平考试《高级系统分析师》押题

  • A.P(S2)和P(S4)
  • B.P(S2)和V(S4)
  • C.V(S2)和P(S4)
  • D.V(S2)和V(S4)
查看答案

相关题库更多 +