求JAVA高手~~定义一个类表示水果~~高手在哪里 哆啦A梦在哪里 奥特曼在哪里 葫芦娃在哪里~ help~

定义一个类表示水果,要求如下:
(1)成员变量有水果名称和重量。
(2)成员变量有水果名称和重量,成员方法包括水果名称和重量的setter和getter方法。
(3)成员变量有水果名称和重量,成员方法包括水果名称和重量的setter和getter方法、构造方法。
(4)成员变量有水果名称和重量,成员方法包括水果名称和重量的getter方法、重载的构造方法、重载的设置成员变量值的方法。
(5)创建这个类的对象,并引用类中定义的成员。

public class Fruit {
private String name;
private double weight;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getWeight() {
return weight;
}

public void setWeight(double weight) {
this.weight = weight;
}
//构造方法
public Fruit(String name,double weight){
this.name = name;
this.weight = weight;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Fruit f = new Fruit("苹果",0.5);
System.out.println(f.getName());//输出名称
System.out.println(f.getWeight());//输出名称
}

}
如果对你有所帮助,请采纳,谢谢!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-10
太简单,拒绝回答
第2个回答  2011-06-10
这不是最基本的吗?追问

= =.刚学不懂。

追答

嗯,看zzxxdd18的,不过他没重载

第3个回答  2011-06-11
没有
相似回答
大家正在搜