📄 wallpaper.java
字号:
/*
* Wallpaper.java E.L. 2001-05-17
*
*/
class Wallpaper extends Material {
private static final double limit = 0.02; // limit for one more width
private double lengthPerRoll; // meter
private double widthPerRoll; // meter
public Wallpaper(String initName, double initPrice, double initLengthPerRoll,
double initWidthPerRoll) {
super(initName, initPrice);
lengthPerRoll = initLengthPerRoll;
widthPerRoll = initWidthPerRoll;
}
public double getLengthPerRoll() {
return lengthPerRoll;
}
public double getWidthPerRoll() {
return widthPerRoll;
}
/*
* This method calculates the number of rolls needed to paper a surface.
*/
public double getMaterialReq(Surface aSurface) {
double lengthSurface = aSurface.getLength();
double heightSurface = aSurface.getWidth();
/* calculate the number of heights */
int noOfHeights = (int) (lengthSurface / widthPerRoll);
double remnant = lengthSurface % widthPerRoll;
if (remnant >= limit) noOfHeights++;
/* calculate the number of rolls */
int noOfRolls;
int noOfHeightsPerRoll = (int) (lengthPerRoll / heightSurface);
if (noOfHeightsPerRoll > 0) {
noOfRolls = noOfHeights / noOfHeightsPerRoll;
remnant = noOfHeights % noOfHeightsPerRoll;
if (remnant >= limit) noOfRolls++;
} else { // the roll is shorter than one height (rarely!)
double totalNoOfMeters = noOfHeights * heightSurface;
noOfRolls = (int) (totalNoOfMeters / lengthPerRoll);
if (totalNoOfMeters % lengthPerRoll >= limit) noOfRolls++;
}
return noOfRolls;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -