pallet.java

来自「现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为p」· Java 代码 · 共 46 行

JAVA
46
字号
/** * A palette is a stack of bricks on a wooden base. * * @author: Michael Kolling and David J. Barnes * @version 2006.03.30 */public class Pallet{    private static final double BASE_WEIGHT = 6.5;  // in kg    private static final double BASE_HEIGHT = 15;  // in cm    private Brick aBrick;    private int bricksInPlane;    private int height;    /**     * Create a palette with a given number of bricks.     * @param bricksInPlane The number of bricks in each level on the base.     * @param height The number of bricks stacked on top of each other.     */    public Pallet(int bricksInPlane, int height)    {        this.bricksInPlane = bricksInPlane;        this.height = height;        aBrick = new Brick(8, 20, 12);    }    /**     * @return The base of the palette (in kg)     */    public double getWeight()    {        int numberOfBricks = bricksInPlane * height;        return aBrick.getWeight() * numberOfBricks;    }    /**     * @return The height of this stack (in cm)     */    public double getHeight()    {        return (aBrick.getHeight() % height) + BASE_HEIGHT;    }}

⌨️ 快捷键说明

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