【发布时间】:2014-07-08 19:05:27
【问题描述】:
我的老师给了我这个任务,我让整个程序完美运行,但我不明白第 4 步中他希望我重载 set 方法以设置去爪值的部分。在程序中,我问了一个真假问题,并使用 Cat 类中的 set 方法来设置布尔值。为什么我需要一个重载方法呢?如果有人可以就这个主题提出一些想法,那就太棒了。谢谢!
1.Create a new class called Cat that includes the functionality below
2.The new class has the attributes of:
name – type String
age – type integer
weight – type double
breed - type String
declawed - type boolean - true for has no claws, false for has claws
3. Be sure your classes have a reasonable complement of constructor, accessor and
mutator methods. Every member variable must have at least one independent accessor and
one independent mutator.
4. Example:
public void setName(String name) mutator used to set name
public void setBreed(String breed) mutator used to set the breed
public void set(Boolean declawed) used to set claws or not
***(You must overload the set method to set deClawed value)****
public String getName() accessor used to get name
public String getBreed() accessor used to get breed
public boolean getBoolean() access used to get the value of declawed
这是正确的输出。
示例运行: 输入 Cat 1 的名称:Sam
输入 Cat 1 的年龄:1
输入 Cat 1 的重量:5
输入 Cat 1 的品种:fluffy1
猫有爪子吗?对还是错?:对
【问题讨论】: