1)定义一个橘类(SouthOrange),包含4个私有成员变量shape,size、color、membrane分别为字符串、单精度浮点型、字符串及整型,表示果实形状、直径大小、果皮颜色、囊瓣数。一个四参构造方法,一个无参构造方法,四个分别设置4个成员变量的方法,四个分别获取成员变量取值的方法,及一个输出方法显示四种属性。
(2)编写测试类,测试SouthOrange。
class SouthOrange{
private String shape;
private float size;
private String color;
private Integer membrane;
SouthOrange(String shape, float size, String color, Integer membrane){
this.shape = shape;
this.size = size;
this.color = color;
this.membrane = membrane;
}
SouthOrange(){}
public String getShape() {
return shape;
}
public void setShape(String shape) {
this.shape = shape;
}
public float getSize() {
return size;
}
public void setSize(float size) {
this.size = size;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Integer getMembrane() {
return membrane;
}
public void setMembrane(Integer membrane) {
this.membrane = membrane;
}
public void show(){
System.out.println("shape = " + this.shape);
System.out.println("size = " + this.size);
System.out.println("color = " + this.color);
System.out.println("membrane = " + this.membrane);
}
}
@Test
public void test001(){
SouthOrange southOrange1 = new SouthOrange();
SouthOrange southOrange2 = new SouthOrange("圆形", 1, "橙色", 1);
southOrange1.setShape("正方形");
southOrange1.setSize(2);
southOrange1.setColor("黑色");
southOrange1.setMembrane(2);
southOrange1.show();
southOrange2.show();
}