⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flooring.java

📁 Java the UML Way 书中所有源码
💻 JAVA
字号:
/*
 * Flooring.java   E.L. 2001-05-17
 *
 */
class Flooring extends Material {
  private static final double limit = 0.02; // limit for one more width
  private double widthOfFlooring;    // meter

  public Flooring(String initName, double initPrice, double initWidth) {
    super(initName, initPrice);
    widthOfFlooring = initWidth;
  }

  public double getWidth() {
    return widthOfFlooring;
  }

  /*
   * We are going to calculate the amount which is needed to cover one surface.
   * The flooring is always placed crosswise relative to the length of the surface.
   * If you want to find the amount the other way, you have to change
   * width and length in the surface argument.
   */
  public double getMaterialReq(Surface aSurface) {
    double lengthSurface = aSurface.getLength();
    double widthSurface = aSurface.getWidth();

    int noOfWidths = (int) (lengthSurface / widthOfFlooring);
    double remnant = lengthSurface % widthOfFlooring;
    if (remnant >= limit) noOfWidths++;
    return noOfWidths * widthSurface;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -