试题详情

试题五(共 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 < names.length;i++) {if (names[i].())﹛return new realCusωmer(name);﹜﹜return ()﹜﹜ Public class CrM﹛Public viod get Customer()﹛Customerfactory()Customer customer1-cf.getCustomer(″rob″);Customer customer2=cf.getCustomer(″rob″);Customer customer3= cf.getCustomer(″Julie″);Customer customer4= cf.getCustomer(″Laura″);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();﹜﹜/*程序输出为:CustomerrobNot Available in Customer DatabaseJulieNot Available in Customer Datable*/int main()﹛CrM*crs=newCrM();Crs->getCustomer();Crs->getCustomer();Delete crs;return();﹜/*程序输出为:CustomerrobNot Available ini Customer DatabaseJulieNot Available in Customer Database