Fraction
属性
int numerator
分子
int denominator
分母
方法
String description()
返回字符串
样例
// 基于对象的如下状态 this: + numerator: 3 + denominator: 4 // 调用后应该会得到 point.description() -> "3/4"
double value()
返回等值小数
样例
// 基于对象的如下状态 this: + numerator: 3 + denominator: 4 // 调用后应该会得到 point.value() -> 0.75
构造方法
()
无参构造,分子分母将分子分母设置为 1
(int numerator, int denominator)
带参构造
(String string)
根据固定格式的 string
构造 Fraction 对象
// 调用构造后 new Fraction("3/4"); // 创建的对象应该处于如下状态 this: + numerator: 3 + denominator: 4
Getter Setter
对 两个属性 分别写 Getter Setter
但要求 对 denominator 属性进行保护,不能让其等于 0