📄 paint.java
字号:
/*
* Paint.java E.L. 2001-08-15
*.
*/
class Paint {
private static final double limit = 0.02; // limit to buy 0.5 liters more
private String name; // idnetification
private double price; // price a liter
private int noOfCoats;
private double noOfSqMPerLiter;
public Paint(String initName, double initPrice, int initNoOfCoats,
double initNoOfSqMPerLiter) {
name = initName;
noOfCoats = initNoOfCoats;
noOfSqMPerLiter = initNoOfSqMPerLiter;
price = initPrice;
}
public String getName() {
return name;
}
public double getPricePerLiter() {
return price;
}
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 getNoOfLiters(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 double getTotalPrice(Surface aSurface) {
return getNoOfLiters(aSurface) * price;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -