阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序使用类来管理员工的通讯地址信息。已知程序的输出为:输出记录:5姓名:王丽华街道地址:中华路15号市:襄樊市省:湖北省邮政编码:430070[Java代码]public class Employee{protected String (1);protected String street;protected String city;protected String prov;protected String post;protected int no;public Empbyee(){}public Employee(String name,String street,String city,String prov,String post, (2) ){this.name=name;this.street=street;this.city=city;this.prov=prov;this.post=post;this.no=no;}public static void main(String[]args){Employee emp=new Employee(“王华”,“中华路15号”,“武汉市”,“湖北省”,“430070”,1);emp.changeName(“王丽华”);(3) (“襄樊市”);emp.changeNo(5);(4);}void changeName(String name){this.name=name;}void changeStreet(String street){this.street=street;}void changeCity(String city){this.city=city;}void changeProv(String prov){this.prov=prov;}void changeNo(int no){(5);}void display(){System.out.println(“输出记录:”+this.no);System.out.Println(“姓名:”+this.name);System.out.println(“街道地址:”+this.street);System.out.println(“市:”+this.city);System.out.println(“省:”+this.prov);System.out.println(“邮政编码:”+this.post);}}

阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。

[说明]

本程序使用类来管理员工的通讯地址信息。已知程序的输出为:

输出记录:5

姓名:王丽华

街道地址:中华路15号

市:襄樊市

省:湖北省

邮政编码:430070

[Java代码]

public class Employee{

protected String (1);

protected String street;

protected String city;

protected String prov;

protected String post;

protected int no;

public Empbyee(){}

public Employee(String name,String street,String city,String prov,String post, (2) ){

this.name=name;

this.street=street;

this.city=city;

this.prov=prov;

this.post=post;

this.no=no;

}

public static void main(String[]args){

Employee emp=new Employee(“王华”,“中华路15号”,“武汉市”,“湖北省”,“430070”,1);

emp.changeName(“王丽华”);

(3) (“襄樊市”);

emp.changeNo(5);

(4);

}

void changeName(String name){this.name=name;}

void changeStreet(String street){this.street=street;}

void changeCity(String city){this.city=city;}

void changeProv(String prov){this.prov=prov;}

void changeNo(int no){(5);}

void display(){

System.out.println(“输出记录:”+this.no);

System.out.Println(“姓名:”+this.name);

System.out.println(“街道地址:”+this.street);

System.out.println(“市:”+this.city);

System.out.println(“省:”+this.prov);

System.out.println(“邮政编码:”+this.post);

}

}


相关考题:

阅读以下说明和java代码,将应填入(n)处的字句写在对应栏内。[说明]本程序中预设了若干个用户名和口令。用户输入正确的用户名后,可以查找对应的口令,一旦输入结束标记“end”,程序结束。[Java代码]import java. io. *:public class User {public String user;public Siring pass;public User() { }public User( String u,String p) {user=u;pass=p;}public String (1) () { return this. user; }public String (2) () { return this. pass; }public static void main(String[] args) {User ua[]={new User("Li","123456"), new User("wang","654321"),new User("Song","666666")};while(true) {InputStreamReader reader = new InputStreamReader(System. in);BufferedReader inpul = new BnfferedReader(reader);System. out. print("Enter your name:");String name = null;try { name = input. readLine();}catch (IOException ex) {}if((3)) break;int i;for (i=0;i<3;i++) {if (name. equals(ua[i]. getUser())){System. out. println("密码:"+ua[i].getPass());(4);}}if ((5)) System. out. println("该用户不存在!");}}}

阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。public (1) {public static String removeNonLetters( (2) ){StringBuffer aBuffer=(3);char aCharacter;for(int i=0; i<original.length();i++){aCharacter=(4);if(Character.isLetter(aCharacter))aBuffer.append( (5) );}return new String(aBuffer);}}public class StringEditorTester{public static void main(String args[]){String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";System.out.println(StringEditor.removeNonLetters(original));}}

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]本程序使用类来管理员工的通讯地址信息。已知程序的输出为:输出记录:5姓名:王丽华街道地址:中华路15号市:襄樊市省;湖北省邮政编码:430070[C++程序]include < iostream, h >include < string, h >class employee.{ protected:char name[10];char street[ 20 ];char city[10];char (1) [10];char post[7];int no;(2):(3) (char [] ,char [] ,char [] ,char [] ,char [] ,int);void changename ( char n [] ) { strcpy ( name, n); }void changestreet( char s[] ) { strcpy(street,s) ;}void changecity ( char c [] ) { strcpy ( city, c ); }void changeprov( char p [] ) { strcpy(prov,p); }void changeno(int nnm) { (4);}void display( );};employee:: (3) (char n[] ,char s[] ,char c[] ,char p1[] ,char p2[] ,int nam){ strcpy(name,n);strcpy ( street, s);strcpy ( city, c);strcpy ( prov, p1 );strcpy ( post, p2 );no = nam; }void employee:: display( ) { cont< <"输出记录: "< <no< <endl;cout< < "姓名: "< < name < < endl;coot < < "街道地址: "< < street < < endl;cout < < "市: "< < city < < endl;cout< <"省: "< <prov < <endl;cout < <"邮政编码: "< < post < < endl;}void main( ) { employee cmp("王华" ,"中华路15号" ,"武汉市","湖北省","430070", 1 );emp. changename( "五丽华" );emp. changecity ( "襄樊市" );emp. changeno(5);(5);

阅读下列说明、图和Java代码,将应填入(n)处的字句写在对应栏内。【说明】已知对某载客车辆(Car)进行类建模,如图7-1所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。【Java代码】class Body{ //此处代码省略 ); //车身类class Passenger{ //此处代码省略 )/ //乘客类class Wheel{ //此处代码省略 ); //车轮类class Driver{ //司机类public String name; //表示第几路公交车司机public Driver(String driverName){name = driverName/) //构造函数};class Engine{//引擎类public String engineNo;//引擎编号public Engine(String engineNo){this.engineNo=engineNo;)//构造函数};public class Car{//汽车类static final int(1)=7; //定义最多载客数static final int MAX WHEELS =5; //定义最多轮胎数protected Engine engine;protected Driver driver;protected Body body=new Body();protected Wheel[] wheels;protected Passenger[]passengers;public Car(Driver driver){ //构造函数(2).driver=driver;engine=new Engine("TX6536型号引擎");wheels=new Wheel[MAX WHEELS];passengers=new Passenger[MAX_PASSENGERS];for(int index=0;index<MAX_WHEELS;index++){wheels[index]=new Wheel();}for(int index=0;index<MAX_PASSENGERS;index++){passengers[index]=null;}}int getPassengerNumber(){//获取车上乘客数量//此处代码省略}void getOnPassenger(Passenger aPassenger){//乘客上车//此处代码省略}void run(){ //开车if((3)){System.out.println("司机尚未上车!");return;}//此处代码省略}public static void main(String args[]){Driver driver=new Driver("第五路公交车司机");Car car=new Car((4));for (int index = 0 ; index < MAX_PASSENGERS; index ++)car.getOnPassenger((5) Passenger());car.run();}}

阅读以下说明、Java代码,将应填入(n)处的字句写在对应栏内。【说明】本程序输出10000之内的所有完全数。完全数是指等于其所有因子和(包括1,但不包括这个数本身)的数。例如:6=1×2×3,6=1+2+3,则6是一个完全数。【程序】public class PerfectNum{Public static void main(String args[]){int count=1;for(int i=1; i<10000; i++){int y=0;for(int j=1; j<i; j++)if((1))y=(2)if((3)){System.out.print( (4) +String.valueOf('\t'));(5)If(count%3==0)System.out.printin();}}}

阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:【c++代码】include1istincludeincludeusing namespace std;class AbstractFile{protected:string name;//文件或目录名称public:void printName(){cout*getChildren()=0; //获得一个目录的子目录或文件};class File:public AbstractFile{public:File(string name){ (1) =name;)void addChild(AbstractFile*file){return ;)void removeChiid(AbstractFile*file){return;}(2) getChildren(){return ( 3 ) ;}};class Folder:public AbstractFile{private:listchildList; //存储子目录或文件public:Folder(string name){ (4) =name;}void addChild(AbstractFile*file){childList.push back(file);}void removeChiid(AbstractFile*file)(chiidList.remove(file);}list*getChildren(){return (5) ;)};voidmain(){//构造一个树形的文件/目录结构AbstractFile*rootFolder=new Folder(“C:\\”);AbstractFile*compositeFolder=flew Folder(”composite”);AbstractFile*windowsFolder=new Folder(”windows”);AbstractFile*file=new File(”TestComposite.java”);rootFolder-addChild(compositeFolder);rootFolder-addChild (windowsFolder);compositeFolder-addChiid(file);)

阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—8所示:【Java代码】import JavA.util.ArrayList;import JavA.util.List;(1)class AbstractFile{protected String name;public void printName(){System.out.println(name);}public abstract boolean addChild(AbstractFile file);public abstract boolean removeChild(AbstractFile file);public abstract ListgetChildren {};}class File extends AbstractFile{public File(String name)(this.name=name;}public boolean addChild(AbstractFile file){return false;}public boolean removeChild(AbstractFile file){return false;}public ListgetChildren(){return (2) ;)}clasS Folder extends AbstractFile{private ListchildList;public Folder(String name){thiS.name=name;this.childList=new ArrayList{};}public boolean addChild(AbstractFile file){return childList.add(file);}public boolean removeChild(AbstractFile file){return childList.remove(file);public (3)getChildren(){return (4) ;)}public class Client{public static void main(String[]args){//构造一个树形的文件/目录结构AbstractFile rootFolder=new Folder(“C:\”’);AbstractFile compositeFolder=new Folder(”composite”);AbstractFile windowsFolder=new Folder(”windows”);AbstractFile file=new File(”TestComposite.java”);rootFOlder.addChild (compositeFolder);rootFolder.addChiid(windowsFolder);compositeFolder.addChild(file);//打印目录文件树printTree(rootFolder);}private static void printTree(AbstractFile ifile){ifile.PrIntName();Listchildren:ifile.getChildren ();if(chiidren==null)return;for(AbstractFile file:children){(5) ;}}}该程序运行后输出结果为:C:\compositeTestComposite.javaWindows

阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}

阅读下列说明、图和Java代码,填补空缺。[说明]已知对某载客车辆(Car)进行类建模,如图13-2所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。[Java代码]class Body{ //此处代码省略 }; //车身类class Passenger{ //此处代码省略 }; //乘客类class Wheel{ //此处代码省略 }; //车轮类class Driver{ //司机类public String name; //表示第几路公交车司机public Driver(String driverName){name=driverName; }//构造函数};class Engine{ //引擎类public String engineNo; //引擎编号public Engine(String engineNo){this.engineNo=engineNo; }//构造函数};public class Car{ //汽车类static final int (1) =7; //定义最多载客数static final int MAX_WHEELS=5; //定义最多轮胎数protected Engine engine;protected Driver driver;protected Body body=new Body( );protected Wheel[]wheels;protected Passenger[]passengers;public Car(Driver driver){ //构造函数(2) .driver=driver;engine=new Engine("TX6536型号引擎");wheels = new Wheel[MAX_WHEELS];passengers=new Passenger[MAX_PASSENGERS];for(int index=0; index<MAX_WHEELS; index++){wheels[index]=new Wheel( );}for(int index=0; index<MAX_PASSENGERS; index++){passengers[index]=null;}}int getPassengerNumber( ){ //获取车上乘客数量//此处代码省略}void getOnPassenger(Passenger aPassenger ){//乘客上车//此处代码省略}void run( ){ //开车if( (3) )(System.out.printin("司机尚未上车!"); return; }//此处代码省略}public static void main(String args[]){Driver driver=new Driver("第五路公交车司机");Car car=new Car( (4) );for(int index=0; index <MAX_PASSENGERS; index++)car.getOnPassenger( (5) Passenger( ));car.run( );}}

阅读以下说明和 Java程序,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单客户关系管理系统(CRM)中通过工厂(CustomerFactory )对象来创建客户(Customer)对象的功能。客户分为创建成功的客户(RealCustomer)和空客户 (NullCustomer)。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图 5-1 所示。图5-1 类图【Java代码】 Abstract class Customer﹛ Protected String name; ( 1 )boolean isNil(); ( 2 )String getName(); ﹜ Class RealCustomer ( 3 )Customer{ Public RealCustomer(String name){ this.name=name; } Public String getName(){ return name ; } Public boolean is Nil() { return false; } ﹜ Class NullCustomer( 4 )Customer﹛ Public String getName()﹛ return Not Available in Customer Database; ﹜ Public boolean isNil() ﹛ return true; ﹜ ﹜ class Customerfactory { public String[] names = {Rob,Joe,Julie}; public Customer getCustomer(String name) { for (int i = 0; i names.length;i++) { if (names[i].( 5 ))﹛ return new RealCustomer(name); ﹜ ﹜ return ( 6 ); ﹜ ﹜ Public class CrM﹛ Public viod get Customer()﹛ Customerfactory( 7 ); Customer customer1-cf.getCustomer(Rob); Customer customer2=cf.getCustomer(Bob); Customer customer3= cf.getCustomer(Julie); Customer customer4= cf.getCustomer(Laura); System.out.println(customers) System.out.println(customer1.getName()); System.out.println(customer2getName()); System.out.println(customer3.getName()); System.out.println(customer4.getName()); ﹜ Public static viod main (String[]arge)﹛ CRM crm =new CRM(); Crm.getCustomer(); ﹜ ﹜ /*程序输出为: Customers rob Not Available in Customer Database Julie Not Available in Customer Database */

阅读下列说明和 C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作井出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员(Waiter)调度厨师制作套餐。现采用生成器(Builder) 模式实现制作过程,得到如图 5-1 所示的类图。图5-1 类图 【C++代码】 includeiostream include string using namespace std; class Pizza { private: string parts; public: void setParts(string parts) { this-parts=parts; } string getParts() { return parts; } }; class PizzaBuilder { protected:Pizza* pizza; public: Pizza* getPizza() { retum pizza; } void createNewPizza() { pizza = new Pizza(); } ( 1 ); } class HawaiianPizzaBuilder :public PizzaBuilder { public: void buildParts() { pizza-setParts(cross +mild + hampineapple); } }; class SpicyPizzaBuider: public PizzaBuilder { public: void buildParts() { pizza-setParts(pan baked +hot + hampineapple); } } Class Waiter{ Private: PizzaBuilder* pizzaBuilder; public: void setPizzaBuilder(PizzaBuilder* pizzaBuilder) { /*设置构建器*/ ( 2 ) } Pizza* getPizza() { return pizzaBuilder-getPizza(); } void construct() { /*构建*/ pizzaBuilder-createNewPizza(); ( 3 ) } }; int main(){ Waiter*waiter=new Waiter(); PizzaBuilder*hawaiian pizzabuilder=new HawaiianPizzaBuilder() ( 4 ); ( 5 ); cout pizza: waiter-getPizza()-getParts() endl; } 程序的输出结果为: pizza: cross + mild + hampineapple

阅读下列说明和 Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员 (Waiter) 调度厨师制作套餐。现采用生成器 (Builder) 模式实现制作过程,得到如图 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 + hampineapp1e}; } class SpicyPizzaBuilder extends PizzaBuilder { public void buildParts() { pizza.setParts(pan baked + hot + pepperonisalami); } } 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 + hampineapple

试题七(共 15 分)阅读下列说明、图和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]已知对某载客车辆(Car)进行类建模,如图 7-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。[Java 代码]class Body{ //此处代码省略 }; //车身类class Passenger{ //此处代码省略 }; //乘客类class Wheel{ //此处代码省略 }; //车轮类class Driver{ //司机类public String name; //表示第几路公交车司机public Driver(String driverName){name = driverName;} //构造函数};class Engine{ //引擎类public String engineNo; //引擎编号public Engine(String engineNo){ this.engineNo = engineNo; } //构造函数};public class Car{ //汽车类static final int (1) = 7; //定义最多载客数static final int MAX_WHEELS = 5; //定义最多轮胎数protected Engine engine;protected Driver driver;protected Body body = new Body();protected Wheel[] wheels;protected Passenger[] passengers;public Car(Driver driver){ //构造函数(2) .driver = driver;engine = new Engine("TX6536 型号引擎");wheels = new Wheel[MAX_WHEELS];passengers = new Passenger[MAX_PASSENGERS];for (int index = 0; index MAX_WHEELS; index++){wheels[index] = new Wheel();}for (int index = 0; index MAX_PASSENGERS; index++){passengers[index] = null;}}int getPassengerNumber(){ //获取车上乘客数量//此处代码省略}void getOnPassenger(Passenger aPassenger ){ //乘客上车//此处代码省略}void run(){ //开车if( (3) ){ System.out.println("司机尚未上车!"); return;}//此处代码省略}public static void main(String args[]){Driver driver = new Driver("第五路公交车司机");Car car = new Car( (4) );for (int index = 0 ; index MAX_PASSENGERS; index ++)car.getOnPassenger( (5) Passenger());car.run();}}

阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。[说明]在一些大型系统中,大多数的功能在初始化时要花费很多时间,如果在启动的时候,所有功能(连不用的功能)都要全面初始化的话,会连带影响到应用软件要花很多时间才能启动。因此常将程序设计成到了实际要使用某种功能的阶段才初始化该功能。以下示例展示了Proxy(代理)模式,PrinterProxy类执行一些比较“轻”的方法——设置名称和取得名称,需要真正执行“重”的方法——真正打印——时才初始Print类。图6-1显示了各个类间的关系。[图6-1][Java代码]//Printable.JavapubliC (1) Printable{public abstract void setPrinterName(String name);public abstract String getprinterName();public abstract void print(String string);}//Printer.Javapublic class Printer implements Printable{private String name;public Printer(){System.out.println("正在产生Printer的对象实例");}public Printer(String name){this.name=name;heavyJob("正在产生Printer的对象实例("+name+")");public void setPrinterName(String name){this.name=name;public String getPrinterName(){return name;public void print(String string){System.out.println("===" +name+" ====");System.out.println(string);}}//PrinterProxy.Javapublic class PrinterProxy (2) Printable{private String name;private Printer real;public PrinterProxy(){}public PrinterProxy(String name){this.name=name;}public gynchronized void setPrinterName(String name){if( (3) ){real.setPrinterName(name);}this.name=name;}public String getprinterName(){return name;}public void print(String string){(4);real.print(string);}private synchronized void realize(){//产生真正的Printer对象if(real==null){real=(5);}}}(1)

试题六(共15分)阅读以下说明和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。【说明】己知某公司按周给员工发放工资,其工资系统需记录每名员工的员工号、姓名、工资等信息。其中一些员工是正式的,按年薪分周发放(每年按52周计算);另一些员工是计时工,以小时工资为基准,按每周工作小时数核算发放。下面是实现该工资系统的Java代码,其中定义了四个类:工资系统类PayRoll,员工类Employee,正式工类Salaried和计时工类Hourly,Salaried和Hourly是Employee的子类。【Java代码】abstract class Employee{protected String name; //员工姓名protected int empCode; //员工号protected double salary; //周发放工资public Employee(int empCode, String name){this.empCode= empCode;this.name= name;}public double getSalary(){return this.salary;}public abstract void pay();}class Salaried (1) Employee{private double annualSalary;Salaried(int empCode, String name, double payRate){super(empCode, name);this.annualSalary= payRate;}public void pay(){salary= (2) ;//计算正式员工的周发放工资数System.out.println(this.name+":"+this.salary);}}class Hourly (3) Employee{private double hourlyPayRate;private int hours;Hourly(int empCode, String name, int hours, double payRate){super(empCode, name);this.hourlyPayRate= payRate;this.hows= hours,}public void pay(){salary= (4) ;//计算计时工的周发放工资数System.out.println(this.name+":"+this.salary);}}public class PayRoll{private (5) employees[]={new Salaried(l001,"Zhang San", 58000.00),//此处省略对其他职工对象的生成new Hourly(1005,"Li", 12, 50.00)};public void pay(Employee e[]){for (int i=0;ie.length; i++){e[i].pay();}}public static void main(String[] args){PayRoll payRoll= new PayRoll();payRoll.pay( (6) );double total= 0.0;for (int i=0;ipayRoll.employees.length; i++){//统计周发放工资总额total+=payRoll.employees[i].getSalary();}System.out.println(total);}}

试题五(共 15 分)阅读以下说明和 Java 程序,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 Jave 代码实现一个简单客户关系管理系统(CrM) 中通过工厂 (Customerrfactory )对象来创建客户(Customer) 对象的功能。客户分为创建成功的客户 (realCustomer) 和空客户(NullCustomer) 。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图 5-1 所示。【Java 代码】Abstract class Customer﹛Protected String name;()boolean isNil()()String getName();﹜ Class realCustomer ()Customer﹛Public realCustomer(String name )﹛ return false; ﹜﹜ Class NullCustomer()Customer﹛Public String getName()﹛ return ″Not Available in Customer Database″; ﹜Public boolean isNil()﹛ return true; ﹜﹜ class Customerfactory {public String[] names = {"rob","Joe","Julie"};public Customer getCustomer(String name) {for (int i = 0; i getCustomer();Crs->getCustomer();Delete crs;return();﹜/*程序输出为:CustomerrobNot Available ini Customer DatabaseJulieNot Available in Customer Database

阅读以下说明和Java代码,将应填入( )处的字句写在答题纸的对栏内。 【说明】 现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡( Card)(信用卡( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。图 5-1 是某支付系统的略类图。import java. util. Array List;import java. util. List;interface PaymentMethod { Public ( 1 )}∥cash、 Debitcard和ltem 实现略,ltem中getPrice( )取当前物品对象的价格abstract class Card (2) { private final String name, num; public Card(string name, String num){this.name= name; this, num = num; } @Overide public String toString ( ) { return String. format(“%s card[name = %s, num =%s}”, this. getType( ), name, num); @override public void pay(int cents) { System. out. printin(“Payed"+ cents+"cents using"+toString( )); this, execute Transaction(cents); } protected abstract String getType( ): protected abstract void execute Transaction(int cents)}class CreditCard ( 3 ) { public CreditCard(String name, String num){ (4) ;} @Override protected String getType( ){ return"CREDIT";} @Override protected void execute Transaction(int cents) { System. out. Println(cents +"paid using Credit Card. "); }} Class Bill {//包含所有购买商品的账单 private List items =new ArrayList( ); public void add(Item item) { items. add(item): } public intgetTotalPrice( ) {/*计算所有 item 的总价格,代码略*/} public void pay( PaymentMethod paymentMethod) {//用指定的支付方式完成支付(5) (getTotalPrice(): }}public class Paymentsystem { public void pay( ) { Bill bill =new Bill ( ); Item item1 = new Item(1234, 10); Item item2 new Item(“5678”, 40); Bill.add(item1); bill. add(item2);//将物品添加到账单中 Bill.pay(new Creditcard("LI SI”, "98765432101"))∥信用卡支付} public static void main(Stringl args) { (6) = new Paymentsystem( ); payment pay( ); }}

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图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 FootDecorator extends Decorator{ public FootDecorator(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 header 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(); } } 程序的输出结果为: 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!

试题六(共 15 分)阅读下列说明和 C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 C++代码实现一个简单客户关系管理系统(CrM)中通过工厂(Customerfactory)对象来创建客户(Customer)对象的功能。客户分为创建成功的客户(realCustomer)和空客户(NullCustomer)。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图6-1 所示。【C++代码】#include#includeusing namespace std; class Customer{protected:string name;public:(1) boll isNil()=0;(2) string getName()=0;﹜; class realCustomer (3){public:realCustomer(string name){this->name=name;﹜bool isNil(){ return false;﹜string getName(){ return name;﹜﹜; class NullCustomer (4) {public:bool isNil(){ return true;﹜string getName(){ return 〝Not Available in Customer Database〞; ﹜﹜;class Customerfactory{public:string names[3]={〝rob〞, 〝Joe〞,〝Julie〞﹜;public:Customer*getCustomer(string name){for (int i=0;igetCustomer(〝rob〞);Customer*customer2=cf->getCustomer(〝Bob〞);Customer*customer3=cf->getCustomer(〝Julie〞);Customer*customer4=cf->getCustomer(〝Laura〞); coutgetName() getName() getName() getName() getCustomer();delete crs;return 0;﹜ /*程序输出为:CustomersrobNot Available in Customer DatabaseJulieNot Available in Customer Database*/

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 5-1 所示。【Java代码】import java.util.*; interface BrakeBehavior{public (1) ;/*其余代码省略*/}class LongWheelBrake implements BrakeBehavior{public void stop(){System.out.println("模拟长轮胎刹车痕迹! ");}/*其余代码省略*/}class ShortWheelBrake implements BrakeBehavior {public void stop(){System.out.println("模拟短轮胎刹车痕迹! ");}/*其余代码省略 */}abstract class Car{protected (2) wheel;public void brake(){ (3) ;}/*其余代码省略*/}class ShortWheelCar extends Car {public ShortWheelCar(BrakeBehavior behavior){(4) ; } /*其余代码省略*/}class StrategyTest{public static void main(String[]args){BrakeBehaviorbrake =new ShortWheelBrake();ShortWheelCar car1= new ShortWheelCar(brake);car1. (5) ;}}

试题五(共 15 分)阅读以下说明和 Java 程序,填补代码中的空缺,将解答填入答题纸的对应 栏内。【说明】以下 Java 代码实现一个简单的聊天室系统(ChatRoomSystem),多个用 户(User)可以向聊天室( ChatRoom)发送消息,聊天室将消息展示给所有用户。 类图如图 5-1 所示。 【Java 代码】 class ChatRoom { public static void showMessage(User user, Strmg message) {System.out.println("[" + user.getName() + "] : " + message);} }classUser{private String name; public String getName() { return name;}public void setName(String name) { this.name = name;}public User(String name) { (1) =name;}public void sendMessage(String message) { (2) (this, message);}}public class Chat:RoomSystem { public void startup() { User zhang= new User("John");User li =new User("Leo"); zhang.sendMessage("Hi! Leo! "); 1i.sendMessage("Hi! John!"); } public void join(User user) { (3) ("Hello Everyone! I am" + user.getName()); }public static void main(String[] args) { ChatRoomSystem crs= (4) ; Crs.startup();Crs.join( (5) )(“Wayne”));}}/*程序运行结果: [John]:Hi! Leol [Leo]:Hi! John![Wayne】:Hello Everyone!Iam Wayne*/

阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图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;} publicvoid 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( ); }}程序的输出结果为: 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!

阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 6-1 所示为其类图。阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】???? 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。?【C++代码】#include #include using namespace std;class Product {private:?string partA, partB;public:?Product() {?? }? ?void setPartA(const string}???? void setPartB(const string}? ?//? 其余代码省略};class Builder {public:? ? ??(1)??;?virtual void buildPartB()=0;? ? ?(2)??;};class ConcreteBuilder1 : public Builder {private:?Product*?? product;public:ConcreteBuilder1() {product = new Product();???? }void buildPartA() {????? (3)???? ("ComponentA"); }?void buildPartB() {????? (4)???? ("ComponentB"); }??Product* getResult() { return product; }//? 其余代码省略};class ConcreteBuilder2 : public Builder {? ??? ? ? ?/*??? 代码省略??? */};class Director {private:? ??Builder* builder;public:??Director(Builder* pBuilder) { builder= pBuilder;}? ??void construct() {????????????????? (5)???? ;?????????????? //? 其余代码省略? ?}??//? 其余代码省略};int main() {? ? ??Director* director1 = new Director(new ConcreteBuilder1());? ?director1->construct();? ? ??delete director1;? ? ?return 0;【Java代码】import jav(6)A.util.*;class Product {? ? ? ?private String partA;? ? ? ?private String partB;? ? ? ??public Product() {}? ? ??public void setPartA(String s) { partA = s; }? ? ? ?public void setPartB(String s) { partB = s; }}interface Builder {? ?public?????? (1)???? ;? ??public void buildPartB();? ? ??public?????? (2)???? ;}class ConcreteBuilder1 implements Builder {? ? ? ?private Product product;? ? ? ?public ConcreteBuilder1() { product = new Product();?? }? ? ? ??public void buildPartA() {????????(3)??("Component A"); }public void buildPartB() {???? ????(4)?? ("Component B"); }? ? ??public Product getResult() { return product;}}class ConcreteBuilder2 implements Builder {?? ? ? ? ?//? 代码省略}class Director {? ? ? ?private Builder builder;? ? ? ?public Director(Builder builder) {this.builder = builder; }public void construct() {? ? ? ? ? ? ? ? ? (5)???? ;? ? ? ? ? ? ? //? 代码省略? ? ??}}class Test {? ? ??public static void main(String[] args) {???????????????? Director director1 = newDirector(new ConcreteBuilder1());???????????????? director1.construct();? ? ? ??}

现有:   1.  class HorseRadish {   2.    // insert code here   3.    protected HorseRadish(int x) {    4.      System.out.println("bok choy");  5.    }  6.  }   7.  class Wasabi extends HorseRadish {   8.    public static void main(String [] args) {   9.      Wasabi w = new Wasabi();  10.   }    11. }   分别插入到第 2 行,哪两项允许代码编译并产生"bok choy" 输出结果?() A、 // just a commentB、 protected HorseRadish() { }C、 protected HorseRadish() { this(42);}D、 protected  HorseRadish() { new HorseRadish (42);}

现有:  class HorseRadish  {      //insert code here  protected HorseRadish (int x)    {      System.out.println ("bok choy");      }      }  class Wasabi extends HorseRadish  {  public static void main (String  []  args){    Wasabi w- new Wasabi();     }     }  分别插入到第2行,哪两项允许代码编译并产生”bok choy”输出结果()A、 protected HorseRadish()  {this (42);}B、  protected HorseRadish()  {}C、  //just a commentD、  protected  HorseRadish()  {  new HorseRadish (42);}

现有:  1. abstract class Color  {  2.protected abstract  String getRGB();     3.  }     4.  5. public class Blue extends Color  {     6.    //insert code here      7.  }  和四个声明:  public String getRGB()  {  return "blue";  }      String getRGB()  {  return  "blue";  )  private  String getRGB()  {  return  "blue";  }      protected String getRGB()  {  return "blue";  )      分别插入到第6行,有几个可以通过编译?()    A、  0B、  1C、  2D、  3

单选题现有:  1. abstract class Color  {  2.protected abstract  String getRGB();     3.  }     4.  5. public class Blue extends Color  {     6.    //insert code here      7.  }  和四个声明:  public String getRGB()  {  return "blue";  }      String getRGB()  {  return  "blue";  )  private  String getRGB()  {  return  "blue";  }      protected String getRGB()  {  return "blue";  )      分别插入到第6行,有几个可以通过编译?()A  0B  1C  2D  3