package chapter5;
import java.math.BigDecimal;
class Rectangle {
private double length;
private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
double findArea() {
return length * width;
}
public void setLength(double length) {
BigDecimal l = new BigDecimal(length);
}
public void setWidth(double width) {
BigDecimal w = new BigDecimal(width);
}
class Cuboid extends Rectangle {
private double height;
public Cuboid(double length, double width, double height) {
super(length, width);
this.height = height;
// TODO 自动生成的构造函数存根
}
double findVolume() {
return super.findArea() * height;
}
}
}
public class Test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Rectangle A = new Rectangle(2.3, 3);
A.findArea();
System.out.println(A.findArea());
}
}
我想计算面积和体积的时候返回的是结果的精确值,具体代码该如何修改,可以直接在setter方法中提前设置吗?
想了想,我描述问题不清楚,谢谢你们的回答了。