?? item.java
字號:
package com.tarena.shoppingcar.entity;import java.io.Serializable;public class Item implements Serializable { private static final long serialVersionUID = -5818580061201193904L; private int id; private Product product = new Product(); private int amount; @SuppressWarnings("unused") private double cost; public int getAmount() { return amount; } public void setAmount(int amount) { this.amount = amount; } public double getCost() { return this.product.getPrice()*this.amount; } public void setCost(double cost) { this.cost = cost; } public int getId() { return id; } public void setId(int id) { this.id = id; } public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } public void addProduct(Product product) { if(this.product.equals(product)){ this.amount = this.amount + 1; setCost(); }else{ this.product = product; this.amount = 1; this.cost = product.getPrice(); } } public void setCost() { this.cost = this.product.getPrice()*this.amount; } @Override public boolean equals(Object obj) { if(obj.getClass() != this.getClass()){ return false; } Item item = (Item)obj; if(this.product.getId() == item.product.getId()) { return true; } return false; } @Override public int hashCode() { return this.id; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -