试题八(共15分)
阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。
[说明]
在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类HeadDecorator 与FootDecorator 分别完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!------------------------这是票据的台头!
这是票据的脚注!
[Java程序代码]
public class SalesTicket {
public void printTicket() {
System.out.println("这是票据正文!");
}
}
public class Decorator extends SalesTicket{
SalesTicket ticket;
}
}
public class FootDecorator extends Decorator{
public FootDecorator(SalesTicket t) {
(2) ;
}
public void printTicket() {
super.printTicket();
System.out.println("这是票据的脚注!");
}
}
public class Main {
public static void main(String[] args) {
T = new HeadDecorator( (3) );
T. (4) ;
System.out.println("------------------------");
T = new FootDecorator( (5) );
T.printTicket();
}
}
public Decorator(SalesTicket t){
ticket = t;
}
public void printTicket(){
if(ticket != null)
ticket.printTicket();
}
}
public class HeadDecorator extends Decorator{
public HeadDecorator(SalesTicket t) {
(1) ;
}
public void printTicket() {
System.out.println("这是票据的台头!");
super.printTicket();