orderitem.java

来自「ssd2 exercise3 的题目和答案」· Java 代码 · 共 81 行

JAVA
81
字号
/**
 * This class maintains the attributes and methods of the OrderItem.
 *
* @author Luorenhu
 * @version  1.0.0
 */
public class OrderItem
{
	
	/* product */
    private Product product;
    
    /* quantity */
    private int quantity;
    
    /**
	 * Constructs an <code>Coffee</code> object.
	 *
	 * @param initialProduct  a <code>Product</code> with the product of the order.
	 * @param initialQuantity  a integer that with the quantity of the order.
	 */
    public OrderItem(Product initialProduct, int initialQuantity)
    {
        product = initialProduct;
        quantity = initialQuantity;
    }
	
	/**
	 * Returns the product of the Order.
	 *
	 * @return  product of the Order.
	 */
    public Product getProduct()
    {
        return product;
    }
	
	/**
	 * Returns the quantity of the Order.
	 *
	 * @return  quantity of the Order.
	 */
    public int getQuantity()
    {
        return quantity;
    }
	
	/**
	 * Modifies the quantity of this order.
	 *
	 * @param newQuantity  a integer with the new quantity of the order.
	 */
    public void setQuantity(int newQuantity)
    {
        quantity = newQuantity;
    }
	
	/**
	 * Returns the value of the Order.
	 *
	 * @return  value of the Order.
	 */
    public double getValue()
    {
        return getProduct().getPrice() * (double)getQuantity();
    }
	
	/**
	 * Returns the string representation of this <code>OrderItem</code>
	 * object (overrides the {@link Object#toString()} method).
	 *
	 * @return  the string representation of this <code>OrderItem</code>
	 *          object.
	 */
    public String toString()
    {
        String message = getQuantity() + " " + getProduct().getCode() + " " + getProduct().getPrice();
        return message;
    }
}

⌨️ 快捷键说明

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