material.java
来自「Java the UML Way 书中所有源码」· Java 代码 · 共 36 行
JAVA
36 行
/*
* Material.java E.L. 2001-08-17
*
*/
import java.text.*;
abstract class Material {
private String name; // identifies the material
private double price; // price per unit
/* These two formats are used in toString() methods */
protected static final DecimalFormat decimalFormat = new DecimalFormat("####0.00");
protected static final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
public Material(String initName, double initPrice) {
name = initName;
price = initPrice;
}
public String getName() {
return name;
}
public double getPricePerUnit() {
return price;
}
public double getTotalPrice(Surface aSurface) {
return getMaterialReq(aSurface) * price;
}
public abstract double getMaterialReq(Surface aSurface);
public String toString() {
return getClass().getName() + ": " + name + ", price " + currencyFormat.format(price);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?