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

📄 orderitem.java

📁 这是我修读美国卡耐基梅隆大学Carnegie Mellon University(CMU)课程ssd3:Object-Oriented Programming and Design时完成的课程设计
💻 JAVA
字号:
/**
 * This class models an item in an order.It contains the following information:
 * </p>
 * <ol>
 * <li>the reference to a {@link Product} object</li>
 * <li>the quantity of the product in the order,a <code>int</code></li>
 * </ol>
 *
 * @author   张维
 * @version  1.0.0
 */
public class OrderItem {

   /* Reference to a Product object */
   private Product product;

   /* Quantity of the product in the order */
   private int quantity; 

   /**
    * Constructs a <code>OrderItem</code> object.
    *
    * @param  initialProduct  the reference to a Product object.
    * @param  initialQuantity  the quantity of the product in the order.
    */
   public OrderItem(Product initialProduct,int initialQuantity) {
        
          product = initialProduct;
          quantity = initialQuantity;
   }

   /**
    * Returns the value of the instance variable product, a reference to a Product object. 
    *
    * @return  the value of the instance variable product, a reference to a Product object.
    */
    public Product getProduct( ) {

       return  product;
    }

    /**
     * Returns the value of the instance variable quantity. 
     *
     * @return  the value of the instance variable quantity.
     */
    public int getQuantity( ) {

       return  quantity;
    }

   
    /**
     * Sets the instance variable <code>quantity</code> to the value of parameter newQuantity. 
     *
     * @param newQuantity  the new quantity.
     */
    public void setQuantity(int newQuantity) {

       quantity = newQuantity;
    }

    /**
     * Returns the product of quantity and price. 
     *
     * @return  the product of quantity and price. 
     */
    public double getValue( ) {
        
       double value = getProduct( ).getPrice( ) * (double)getQuantity( );
       return value;
    }

    /**
     * Returns the string representation of an OrderItem object.
     *
     * @return  the string representation of an OrderItem object.
     */
    public String toString( ) {

        return  getQuantity( ) + " " + getProduct( ).getCode( ) + " " + getProduct( ).getPrice( );
    }
}

⌨️ 快捷键说明

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