阅读以下说明和 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
*/