第一组: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;
}
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;
}
return suppliercode = i;
}后面几组没有编译错误,只是很多不符合编程规范罢了
public Integer SetSupplierCode(Integer int) {
suppliercode = int;
}
Integer 改为 void
suppliercode = i;
}int 是JAVA默认的保留字,不可以作为变量名,set方法是赋予值,不需要返回值,返回类型应该为void。后面几组没有编译问题,但是命名很不规范
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、照我说这样改了还是有问题,其实值与数据因该分开的。
*/
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语言中默认的保留字,不可以作为变量名。
yinwenjie(java入门中):你是用WASD做的吧,嘿嘿!
temptation81(向左.向右.向前) :就是以上四组类或有问题,或有需完善的地方。
public Integer SetSupplierCode(Integer int) {
suppliercode = int;
return suppliercode;//<-------
}
改进建议:
1,类名及构造函数首字母大写。
2,方法首字母小写。
改为 return (Integer)source 就更清楚些
第三组没有什么问题
第四组也没问题。
呵呵,个人看法。
要加入setEngineSize(int engineSize)及setStarted(boolean start)方法;
* 刚刚忘说了,第一组中你的类名应该大写
*
* 以下是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();
}}
是第三组:
要加入setEngineSize(int engineSize)及setStarted(boolean start)方法;
private String name; public Person(String name) {
this.name = name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
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();
}
}
private String name; public Person(String name) {
this.name = name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}第四组修改,今天真晦气,提交几次都不成功
把 public void startEngine() {
isStarted = true;
} public void stopEngine() {
isStarted = false;
}
上移到Engine 类中
yinwenjie(java入门中):这几组类都是这样的问题,编译没有问题,但是从概念的角度是错误的,我是这样认为的。
* 对不起,刚刚发的第二组应该是第三组,第二组大家说了很多,没必要写了(至少我没看过这样的写法,算是孤陋寡闻了)。
*
* 第四组,
* */
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;
}
}
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;}
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实例.
----------------
第四组
不知所云~
1. 构造函数太繁琐,建议修改为:
public supplier(Integer supplierCode, String zipCode) {
this.zipCode= zipCode;
this.suppliercode = supplierCode;
}
修改为:
public supplier(Integer supplierCode, String zipCode) {
----this(supplierCode);-------
this.zipCode= zipCode;
}
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 在线试用.