试题六(共15分)阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。【Java代码】import java.util.*;(1) class Beverage { //饮料String description = "Unknown Beverage";public (2) (){return description;}public (3) ;}abstract class CondimentDecorator extends Beverage { //配料(4) ;}class Espresso extends Beverage { //蒸馏咖啡private final int ESPRESSO_PRICE = 25;public Espresso() { description="Espresso"; }public int cost() { return ESPRESSO_PRICE; }}class DarkRoast extends Beverage { //深度烘焙咖啡private finalint DARKROAST_PRICE = 20;public DarkRoast() { description = "DarkRoast"; }public int cost(){ rcturn DARKROAST PRICE; }}class Mocha extends CondimentDecorator { //摩卡private final int MOCHA_PRICE = 10;public Mocha(Beverage beverage) {this.beverage = beverage;}public String getDescription() {return beverage.getDescription0 + ", Mocha";}public int cost() {return MOCHA_PRICE + beverage.cost();}}class Whip extends CondimentDecorator { //奶泡private finalint WHIP_PRICE = 8;public Whip(Beverage beverage) { this.beverage = beverage; }public String getDescription() {return beverage.getDescription()+", Whip";}public int cost() { return WHIP_PRICE + beverage.cost(); }}public class Coffee {public static void main(String args[]) {Beverage beverage = new DarkRoast();beverage=new Mocha( 5 );beverage=new Whip ( 6 );System.out.println(beverage.getDescription() +"¥" +beverage.cost());}}编译运行上述程序,其输出结果为:DarkRoast, Mocha, Whip ¥38
试题六(共15分)
阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
某咖啡店当卖咖啡时,可以根据顾客的要求在其中加入各种配料,咖啡店会根据所加入的配料来计算费用。咖啡店所供应的咖啡及配料的种类和价格如下表所示。
【Java代码】
import java.util.*;
(1) class Beverage { //饮料
String description = "Unknown Beverage";
public (2) (){return description;}
public (3) ;
}
abstract class CondimentDecorator extends Beverage { //配料
(4) ;
}
class Espresso extends Beverage { //蒸馏咖啡
private final int ESPRESSO_PRICE = 25;
public Espresso() { description="Espresso"; }
public int cost() { return ESPRESSO_PRICE; }
}
class DarkRoast extends Beverage { //深度烘焙咖啡
private finalint DARKROAST_PRICE = 20;
public DarkRoast() { description = "DarkRoast"; }
public int cost(){ rcturn DARKROAST PRICE; }
}
class Mocha extends CondimentDecorator { //摩卡
private final int MOCHA_PRICE = 10;
public Mocha(Beverage beverage) {
this.beverage = beverage;
}
public String getDescription() {
return beverage.getDescription0 + ", Mocha";
}
public int cost() {
return MOCHA_PRICE + beverage.cost();
}
}
class Whip extends CondimentDecorator { //奶泡
private finalint WHIP_PRICE = 8;
public Whip(Beverage beverage) { this.beverage = beverage; }
public String getDescription() {
return beverage.getDescription()+", Whip";
}
public int cost() { return WHIP_PRICE + beverage.cost(); }
}
public class Coffee {
public static void main(String args[]) {
Beverage beverage = new DarkRoast();
beverage=new Mocha( 5 );
beverage=new Whip ( 6 );
System.out.println(beverage.getDescription() +"¥" +beverage.cost());
}
}
编译运行上述程序,其输出结果为:
DarkRoast, Mocha, Whip ¥38