軟件設(shè)計師案例分析當天每日一練試題地址:www.shundajiancai.com/exam/ExamDayAL.aspx?t1=4
往期軟件設(shè)計師每日一練試題匯總:www.shundajiancai.com/class/27/e4_1.html
軟件設(shè)計師案例分析每日一練試題(2022/10/29)在線測試:www.shundajiancai.com/exam/ExamDayAL.aspx?t1=4&day=2022/10/29
點擊查看:更多軟件設(shè)計師習題與指導
軟件設(shè)計師案例分析每日一練試題內(nèi)容(2022/10/29)
閱讀下列說明和java代碼,將應(yīng)填入  (n)  處的字句寫在答題紙的對應(yīng)欄內(nèi)。 
【說明】 
某發(fā)票(lnvoice)由抬頭(Head)部分、正文部分和腳注(Foot)部分構(gòu)成?,F(xiàn)采用裝飾(Decorator)模式實現(xiàn)打印發(fā)票的功能,得到如圖6-1所示的類圖。

【java代碼】 class invoice{ 
public void printInvoice(){ 
System.out.println ( "This is the content of the invoice!"); 
} 
} 
class Decorator extends Invoice { 
protected Invoice ticket; 
public Decorator(lnvoice t){ 
ticket = t; } 
public void printInvoice(){ 
if(ticket != null) 
(1)	; 
} 
} 
class HeadDecorator extends Decorator{ 
public HeadDecorator(lnvoice t){ 
super(t); 
} 
public void printInvoice (){ 
Systent.out.println( "This is the header of the invoice! "); 
(2)	; 
} 
} 
class FootDecorator extends Decorator { 
public FootDecorator(Invoice t){ 
super(t); 
} 
public void printlnvoice(){
( 3)        ; 
Systent.out.println( "This is the footnote of the invoice! "); 
} 
} 
Class test { 
public static void main(String[] args){ 
Invoice t =new Invioce(); 
Invoice ticket; 
ticket=     (4)       ; 
ticket.printInvoice(); 
Systent.out.println(“------------------“); 
ticket=       (5)       ; 
ticket.printInvoice();    } } 
程序的輸出結(jié)果為: 
This is the header of the invoice! 
This is the content of the invoice! 
This is the footnote of the invoice! 
---------------------------- 
This is the header of the invoice! 
This is the footnote of the invoice!
信管網(wǎng)試題答案與解析:www.shundajiancai.com/st/381743190.html
信管網(wǎng)考友試題答案分享:
信管網(wǎng)試題答案與解析:
www.shundajiancai.com/st/381743190.html