第一组:package com.exercise1;public class supplier {    public supplier(Integer supplierCode) {
        this.suppliercode = supplierCode;
    }    public supplier(Integer supplierCode, String zipCode) {
        this.zipCode= zipCode;
        this.suppliercode = supplierCode;
    }    public supplier(String name, String zipCode, String telephone) {
        this.name = name;
        this.zipCode = zipCode;
        this.telephone = telephone;
    }    public supplier(String name, String zipCode, String telephone, Integer suppliercode) {
        this.name = name;
        this.zipCode = zipCode;
        this.telephone = telephone;
        this.suppliercode = suppliercode;
    }    public Integer GetSupplierCode() {
        return suppliercode;
    }    public Integer SetSupplierCode(Integer int) {
        suppliercode = int;
    }
    public String name;
    public String zipCode;
    public String telephone;
    // supplierCode is mandatory, every supplier must have one
    public Integer suppliercode;}第二组:package com.exercise2;
public class CopyFactory {    public CopyFactory() {
    }
    public Object createCopy(Object source) {
        if (source instanceof Integer) {
            return new Integer(((Integer)source).intValue());
        }
        if (source instanceof Long) {
            return new Long(((Long)source).longValue());
        }
        if (source instanceof Float) {
            return new Float(((Float)source).floatValue());
        }
        return null;
    }
        
}第三组:
/*
  Car类
 */
package com.exercise3;/**
 */                         
public class Car extends Engine {    public Car(int engineSize) {
        super(engineSize);
    }    public void startEngine() {
        isStarted = true;
    }    public void stopEngine() {
        isStarted = false;
    }}/*
 Engine 类
 */
package com.exercise3;public class Engine {    public Engine(int engineSize) {
        this.engineSize = engineSize;
    }    public boolean isStarted() {
        return isStarted;
    }    public int getEngineSize() {
        return engineSize;
    }        protected boolean isStarted;
    private int engineSize;
}第四组:
/*
  Company类  
 */
package com.exercise4;import java.util.Collection;
import java.util.ArrayList;/**
 * Class for a company
 */
public class Company {    public Company(String name) {
        this.name = name;
        this.staff = new ArrayList();
    }    public String getName() {
        return name;
    }    public Collection getStaff() {
        return staff;
    }    private String name;
    private ArrayList staff;
}/*
  Person类 
 */
package com.exercise4;
public class Person {
    public Person(String name) {
        _name = name;
    }
    public String getName() {
        return _name;
    }
    private String _name;
}

解决方案 »

  1.   

    第一组,改正为public Integer SetSupplierCode(Integer i) {
         return suppliercode = i;
    }后面几组没有编译错误,只是很多不符合编程规范罢了
      

  2.   

    第一组
    public Integer SetSupplierCode(Integer int) {
            suppliercode = int;
        }
    Integer 改为 void
      

  3.   

    第一组 改为public void SetSupplierCode(Integer i) {
           suppliercode = i;
    }int 是JAVA默认的保留字,不可以作为变量名,set方法是赋予值,不需要返回值,返回类型应该为void。后面几组没有编译问题,但是命名很不规范
      

  4.   

    第一组:
    public class Supplier {
    private String name;
    private String zipCode;
    private String telephone;
        // supplierCode is mandatory, every supplier must have one
    private int suppliercode;

    public Supplier(int supplierCode) {
            this.suppliercode = supplierCode;
        }    public Supplier(int supplierCode, String zipCode) {
            this.zipCode= zipCode;
            this.suppliercode = supplierCode;
        }    public Supplier(String name, String zipCode, String telephone, int suppliercode) {
            this.name = name;
            this.zipCode = zipCode;
            this.telephone = telephone;
            this.suppliercode = suppliercode;
        }
        
    /**
     * @return Returns the name.
     */
    public String getName() {
    return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name) {
    this.name = name;
    }
    /**
     * @return Returns the suppliercode.
     */
    public int getSuppliercode() {
    return suppliercode;
    }
    /**
     * @param suppliercode The suppliercode to set.
     */
    public void setSuppliercode(int suppliercode) {
    this.suppliercode = suppliercode;
    }
    /**
     * @return Returns the telephone.
     */
    public String getTelephone() {
    return telephone;
    }
    /**
     * @param telephone The telephone to set.
     */
    public void setTelephone(String telephone) {
    this.telephone = telephone;
    }
    /**
     * @return Returns the zipCode.
     */
    public String getZipCode() {
    return zipCode;
    }
    /**
     * @param zipCode The zipCode to set.
     */
    public void setZipCode(String zipCode) {
    this.zipCode = zipCode;
    }
    }
    /**
     * 1、一般都是int,而不是Integer
     * 2、你的变量需要被封装,而public没有达到封装的目的,应该用private
     * 3、get、set方法知道吧
     * 4、变量声明放在最前面
     * 5、照我说这样改了还是有问题,其实值与数据因该分开的。
     */
      

  5.   

    第一组改为这样public class supplier { public supplier(Integer supplierCode) {
    this.suppliercode = supplierCode;
    } public supplier(Integer supplierCode, String zipCode) {
    this.zipCode = zipCode;
    this.suppliercode = supplierCode;
    } public supplier(String name, String zipCode, String telephone) {
    this.name = name;
    this.zipCode = zipCode;
    this.telephone = telephone;
    } public supplier(String name, String zipCode, String telephone,
    Integer suppliercode) {
    this.name = name;
    this.zipCode = zipCode;
    this.telephone = telephone;
    this.suppliercode = suppliercode;
    } public Integer getSupplierCode() {
    return suppliercode;
    } public void setSupplierCode(Integer i) {
    suppliercode = i;
    } private String name; private String zipCode; private String telephone; // supplierCode is mandatory, every supplier must have one
    private Integer suppliercode;}虽然不知道为什么要用Integer这个类来做变量suppliercode的类型,但是如果不是特殊调用的话,建议改为基本型别 int型,所有的全局变量建议用private 封装,安全性更高public void setSupplierCode(Integer i) {
    suppliercode = i;
    }
    这个方法是set方法,一般作为赋值用,返回类型应该为void,不需要返回值,int是JAVA语言中默认的保留字,不可以作为变量名。
      

  6.   

    第一组的问题比较清楚,关键是以后几组的问题与不完善的地方。
     yinwenjie(java入门中):你是用WASD做的吧,嘿嘿!
     temptation81(向左.向右.向前) :就是以上四组类或有问题,或有需完善的地方。
      

  7.   

    第一组:
        public Integer SetSupplierCode(Integer int) {
            suppliercode = int;
            return suppliercode;//<-------
        }
    改进建议:
    1,类名及构造函数首字母大写。
    2,方法首字母小写。
      

  8.   

    第二组没有问题但return new Integer(((Integer)source).intValue());
    改为            return (Integer)source   就更清楚些
    第三组没有什么问题
    第四组也没问题。
    呵呵,个人看法。
      

  9.   

    j2me_home(魔·天使) :你想的跟我的理解一致,只是我觉得其他变量也应该用get和set来取存值,就跟yinwenjie(java入门中)写的一样。其他的几组有什么意见吗?
      

  10.   

    第二组:
    要加入setEngineSize(int engineSize)及setStarted(boolean start)方法;
      

  11.   

    j2me_home(魔·天使) :你想的跟我的理解一致,只是我觉得其他变量也应该用get和set来取存值,就跟yinwenjie(java入门中)写的一样。其他的几组有什么意见吗?
      

  12.   

    第二组:/**
     * 刚刚忘说了,第一组中你的类名应该大写
     * 
     * 以下是Engine类
     * */
    public class Engine {
    private boolean isStarted;
        private int engineSize;
        
    public Engine(int engineSize) {
            this.engineSize = engineSize;
        }

    public void startEngine(){
    this.isStarted = false;
    }

    public void stopEngine(){
    this.isStarted = true;
    }

    /**
     * @return Returns the engineSize.
     */
    public int getEngineSize() {
    return engineSize;
    }
    }
    /**
     * 这是类的更改,照我说,这应该是初学的错误了。问题太多,没法列出了。
     * */
    /**
     * 发动机和汽车的关系是一个聚合,而不是继承,
     * 这是典型的滥用继承
     * */
    public class Car {
    private Engine engine;
    public Car(int engineSize) {
            this.engine = new Engine(engineSize);
        }    public void startEngine() {
            this.engine.startEngine();
        }    public void stopEngine() {
            this.engine.stopEngine();
        }}
      

  13.   

    看窜了^_^:
    是第三组:
    要加入setEngineSize(int engineSize)及setStarted(boolean start)方法;
      

  14.   

    BasaraTracy(不屈斗志) :说的很对,就是考设计模式和重构的,概念性的东西很强。答案需要大家的集思广益,不知道这个帖子和大家的回答能不能给大家带来什么启示!
      

  15.   

    第四组修改public class Person {
    private String name; public Person(String name) {
    this.name = name;
    } public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    }
    }
      

  16.   

    第二组:package com.exercise2;
    public class CopyFactory {    public CopyFactory() {
        }    public Integer createCopy(Integer source) {
                return source.clone();
        }
        public Long createCopy(Long source) {
                return source.clone();
        }
        public Float createCopy(Float source) {
                return source.clone();
        }
    }
      

  17.   

    public class Person {
    private String name; public Person(String name) {
    this.name = name;
    } public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    }
    }第四组修改,今天真晦气,提交几次都不成功
      

  18.   

    第三组
     把   public void startEngine() {
            isStarted = true;
        }    public void stopEngine() {
            isStarted = false;
        }
    上移到Engine 类中
      

  19.   

    shujip(书机破) :能否解释一下你为什么这样子改呢?
    yinwenjie(java入门中):这几组类都是这样的问题,编译没有问题,但是从概念的角度是错误的,我是这样认为的。
      

  20.   

    j2me_home(魔·天使):你的思路跟我挺象的,但总觉得好像还有缺憾。我也是提交好几次失败,呵呵!
      

  21.   

    /**
     * 对不起,刚刚发的第二组应该是第三组,第二组大家说了很多,没必要写了(至少我没看过这样的写法,算是孤陋寡闻了)。
     * 
     * 第四组,
     * */
    public class Person {
    private String _name;

    /**
     * @return Returns the _name.
     */
    public String get_name() {
    return _name;
    }
    /**
     * @param _name The _name to set.
     */
    public void set_name(String _name) {
    this._name = _name;
    }
    }Company:
    /**
     * 按照我的理解,一个公司应该包括很多职工,所以用集合,这没错,
     * 但是不管怎样,我们应该写方法把对象加入集合,是吧。
     * */
    import java.util.ArrayList;
    import java.util.Collection;
    public class Company {
    private ArrayList staff;
    private String name;

    public Company(String name) {
            this.name = name;
            this.staff = new ArrayList();
        }

    public void addPerson(Person companyPerson){
    /*这里应该再加上判断*/
    this.staff.add(companyPerson);
    }

    public Collection getStaff() {
    /*这里这种返回形式,无可厚非*/
            return staff;
        }

    /**
     * @return Returns the name.
     */
    public String getName() {
    return name;
    }
    }
      

  22.   

    我用的是Eclipse哈,不是什么WASD这几组其实是在考有没有真正了解面向对象的思想,第一组我认为是在考封装,第二组是在考接口,或者说是向上转型,第三组是在考继承、依赖。第四组大概考了一下集合,小弟才疏学浅欢迎大家批评、扔拖鞋,我数1、2、3开始仍!!
      

  23.   

    第一组
    package com.exercise1;public class supplier {    public supplier(int supplierCode) {
            this.suppliercode = supplierCode;
        }    public supplier(int supplierCode, String zipCode) {
            this(suppliercode) = supplierCode;
            this.zipCode= zipCode;
            
        }    public supplier(String name, String zipCode, String telephone) {
            this.name = name;
            this.zipCode = zipCode;
            this.telephone = telephone;
        }    public supplier(String name, String zipCode, String telephone, int suppliercode) {
            this(name, zipCode, telephone)
            this.suppliercode = suppliercode;
        }    public Integer GetSupplierCode() {
            return suppliercode;
        }    public Integer SetSupplierCode(int i) {
            suppliercode = i;
        }
        private String name;
        private String zipCode;
        private String telephone;
        // supplierCode is mandatory, every supplier must have one
        private int suppliercode;}
      

  24.   

    yinwenjie(java入门中) :WASD其实及时ibm websphere application studio developer,我刚刚懒得写了,跟Eclipse其实是一家人,呵呵。
      

  25.   

    第一组:
    1. 构造函数太繁琐,建议修改为:
     public supplier(Integer supplierCode, String zipCode) {
    this.zipCode= zipCode;
    this.suppliercode = supplierCode;
    }
    修改为:
    public supplier(Integer supplierCode, String zipCode) {
    supplier(supplierCode);
    this.zipCode= zipCode;
    }
    2. 声明了get set方法的属性,应该声明为private
    ----------------
    第二组
    既然为 简单factory 方法,就把构造函数声明为private, 将creatCopy()方法
    声明为static类型的.
    ----------------
    第三组
    Car怎么可以继承Engine?本来就不是is-a的关系嘛!应该是has-a
    建议在Car中定一个Engine实例.
    ----------------
    第四组
    不知所云~
      

  26.   

    第一组:
    1. 构造函数太繁琐,建议修改为:
    public supplier(Integer supplierCode, String zipCode) {
    this.zipCode= zipCode;
    this.suppliercode = supplierCode;
    }
    修改为:
    public supplier(Integer supplierCode, String zipCode) {
    ----this(supplierCode);-------
    this.zipCode= zipCode;
    }
      

  27.   

    eform表单设计器是一个在IE浏览器中可视化的设计软件界面的工具。无论是输入界面还是报表界面,无论是简单的输入查询还是复杂的逻辑处理。都可以由eform设计出来。 
     
         eform表单设计器适用于网上OA系统的自定义表单模块,工作流系统的自定义表单模块,信息管理系统方面的软件开发项目等等。 eprint自定义打印是一个页面套打工具.它直接在IE浏览器中可视化的设计各种复杂的打印模版,
    能够解决在IE浏览器中打印各种复杂的中国式报表及票据。详见: http://218.30.103.110:8080/eprint/index.htm
    方成eform表单设计器,纯BS结构.100%开放源码.可以在 http://218.30.103.110:8080/eform/index.html 在线试用.