paint.java
来自「Java the UML Way 书中所有源码」· Java 代码 · 共 43 行
JAVA
43 行
/*
* Paint.java E.L. 2001-08-15
*.
*/
class Paint extends Material {
private static final double limit = 0.02; // limit to buy 0.5 liters more
private int noOfCoats;
private double noOfSqMPerLiter;
public Paint(String initName, double initPrice, int initNoOfCoats,
double initNoOfSqMPerLiter) {
super(initName, initPrice);
noOfCoats = initNoOfCoats;
noOfSqMPerLiter = initNoOfSqMPerLiter;
}
public int getNoOfCoats() {
return noOfCoats;
}
public double getNoOfSqMPerLiter() {
return noOfSqMPerLiter;
}
/*
* This method calculates the amount of paint required to cover the surface.
* The result is rounded off upward to the nearest 0.5 liters.
*/
public double getMaterialReq(Surface aSurface) {
double area = aSurface.getArea();
double noOfLiters = area * noOfCoats / noOfSqMPerLiter;
int noOfLitersInteger = (int) noOfLiters;
double more = noOfLiters - noOfLitersInteger;
if (more >= 0.5 + limit) return noOfLitersInteger + 1.0;
else if (more >= limit) return noOfLitersInteger + 0.5;
else return noOfLitersInteger;
}
public String toString() {
return super.toString() + ", no. of coats: " + noOfCoats + ", no. of sqm/liter: "
+ decimalFormat.format(noOfSqMPerLiter);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?