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

📄 substance.java

📁 java设计模式源码
💻 JAVA
字号:
package com.oozinoz.chemical;

/*
 * Copyright (c) 2001, 2005. Steven J. Metsker.
 * 
 * Steve Metsker makes no representations or warranties about
 * the fitness of this software for any particular purpose, 
 * including the implied warranty of merchantability.
 *
 * Please use this software as you wish with the sole
 * restriction that you may not claim that you wrote it.
 */

/**
 * This class represents a batch of chemicals.
 */
public class Substance {
    private String name;

    private String symbol;

    private double atomicWeight;

    private double grams;

    /**
     * Model a batch of stuff.
     * 
     * @param name
     *            The name of this substance, such as "Saltpeter."
     * @param symbol
     *            The chemical symbol for this substance, such as "KNO3."
     * @param atomicWeight
     *            The atomic weight of this substance (101 for saltpeter).
     * @param grams
     *            The mass of this batch of substance.
     */
    public Substance(String name, String symbol, double atomicWeight,
            double grams) {
        this.name = name;
        this.symbol = symbol;
        this.atomicWeight = atomicWeight;
        this.grams = grams;
    }

    /**
     * @return The name of this substance, such as "Saltpeter."
     */
    public String getName() {
        return name;
    }

    /**
     * @return The chemical symbol for this substance, such as "KNO3."
     */
    public String getSymbol() {
        return symbol;
    }

    /**
     * @return The atomic weight of this substance (e.g. 101 for saltpeter).
     */
    public double getAtomicWeight() {
        return atomicWeight;
    }

    /**
     * @return The mass of this batch of substance.
     */
    public double getGrams() {
        return grams;
    }

    /**
     * @return The number of moles in this batch.
     */
    public double getMoles() {
        return grams / atomicWeight;
    }
}

⌨️ 快捷键说明

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