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

📄 floorcalculations.java

📁 Java the UML Way 书中所有源码
💻 JAVA
字号:
/*
 * FloorCalculations.java   E.L. 2001-08-10
 *
 * In this file you'll find two classes:
 * The Surface class and the FloorCalculations class.
 * The main() method is found in the FloorCalculations class,
 * and this method acts as a test program for the Surface class.
 */

class Surface {
  private String name;  // for identification purposes
  private double length;
  private double width;

  public Surface(String initName, double initLength, double initWidth) {
    name = initName;
    length = initLength;
    width = initWidth;
  }

  public String getName() {
    return name;
  }

  public double getLength() {
    return length;
  }

  public double getWidth() {
    return width;
  }

  public double getArea() {
    return width * length;
  }

  public double getCircumference() {
    return 2 * (length + width);
  }
}

/*
 * We are going to test the Surface class.
 * First we instantiate an object of the class,
 * then we retrieve the data from the object and
 * present them to the user. By doing this we will
 * prove that the object really contains the correct data
 * and performs its calculations correctly.
 */
class FloorCalculations {
  public static void main(String[] args) {
    
    /* Step 1: We instantiate an object of the class. */
    Surface aFloor = new Surface("Mary's floor", 4.8, 2.3);

    /* Step 2: We retrieve data from the object,
       and we let the object perform calculations. */
    String name = aFloor.getName();
    double width = aFloor.getWidth();
    double length = aFloor.getLength();
    double area = aFloor.getArea();
    double circumference = aFloor.getCircumference();

    /* Step 3: We present the results on the screen for control. */
    System.out.println("Information about the floor with the name: " + name + ":");
    System.out.println("Width: " + width);
    System.out.println("Length: " + length);
    System.out.println("Area: " + area);
    System.out.println("Circumference: " + circumference);
  }
}

/* Example Run:
Information about the floor with the name: Mary's floor:
Width: 2.3
Length: 4.8
Area: 11.04
Circumference: 14.2
*/

⌨️ 快捷键说明

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