摘要:希賽網(wǎng)整理了2017上半年軟件設計師考試下午真題,以下是第六部分。
希賽網(wǎng)整理了2017上半年軟件設計師考試下午真題,以下是第六部分。
試題六(共15分)
閱讀下列說明和Java代碼,將應填入(n)處的字句寫在答題紙的對應欄內。
【說明】
某快餐廳主要制作并出售兒童套餐,一般包括主餐(各類比薩)、飲料和玩具,其餐品種類可能不同,但其制作過程相同。前臺服務員(Waiter)調度廚師制作套餐?,F(xiàn)采用生成器(Builder)模式實現(xiàn)制作過程,得到如圖6-1所示的類圖。
【Java代碼】
class Pizza {
private String parts;
public void setParts(String parts) {this.parts = parts;}
public String toString() {return this.parts;}
}
abstract class PizzaBuilder {
protected Pizza pizza;
public Pizza getPizza() {return pizza;}
public void createNewPizza() { pizza = new Pizza();}
public (1) ;
}
class HawaiianPizzaBuilder extends PizzaBuilder {
public void buildParts() {pizza.setParts("cross + mild + ham&pineapp1e”};
}
class SpicyPizzaBuilder extends PizzaBuilder {
public void buildParts() { pizza.setParts("pan baked + hot + pepperoni&salami");}
}
class Waiter {
private PizzaBuilder pizzaBuilder;
public void setPizzaBuilder(PizzaBuilder pizzaBuilder) { /*設置構建器*/
(2) ;
}
public Pizza getPizza(){ return pizzaBuilder.getPizza(); }
public void construct() {/*構建*/
pizzaBuilder.createNewPizza();
(3) ;
}
}
Class FastFoodOrdering {
public static viod mainSting[]args) {
Waiter waiter = new Waiter();
PizzaBuilder hawaiian_pizzabuilder = new HawaiianPizzaBuilder();
(4);
(5);
System.out.println("pizza: " + waiter.getPizza());
}
}
程序的輸出結果為:
Pizza:cross+mild+ham&pineapple
軟考備考資料免費領取
去領取