product.java

来自「web开发经典案例shoppingcart的EJB实现其entity部分」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * Product.java
 *
 * Created on 2008年6月2日, 上午9:33
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package stateful;

import java.io.Serializable;

/**
 *
 * @author teacher
 */
public class Product implements Serializable{
    private String name;
    private double price;
    /** Creates a new instance of Product */
    public Product() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public boolean equals(Object obj) {
        boolean retValue = false;
        
        if(obj instanceof Product){
            Product p = (Product)obj;
            retValue = p.getName().equals(name) && p.getPrice() == price;
        }
        return retValue;
    }

    public int hashCode() {
        return name.hashCode() ^ new Double(price).hashCode();
    }
    
    
    
}

⌨️ 快捷键说明

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