📄 shoppingcartitem.java
字号:
package com.wrox.shop;/** * Models a shopping cart item consisting of a Book and a quantity. */public class ShoppingCartItem { private final Book book; private int quantity; /** Creates a new shopping cart item * @param book The book to create the item for. */ public ShoppingCartItem(Book book) { super(); this.book = book; this.quantity = 1; } /** * Retrieves the Book. * @return The Book. */ public Book getBook() { return book; } /** * Retrieves the quantity for the book. * @return The quantity. */ public int getQuantity() { return quantity; } /** * Sets the quantity for the book. * @param quantity The desired quantity. */ public void setQuantity(int quantity) { this.quantity = quantity; } /** Two items are equal if they both have the same book. * @param obj The object to compare to. * @return <code>true</code> if the object is a ShoppingCartItem * and contains the same book */ public boolean equals(Object obj) { return obj instanceof ShoppingCartItem && equals((ShoppingCartItem)obj); } /** Two items are equal if they both have the same book. * @param that The ShoppingCartItem to compare to. * @return <code>true</code> if the object is a ShoppingCartItem * and contains the same book */ public boolean equals(ShoppingCartItem that) { return this.book == that.book; } /** Overridden to be consistent with equals(). * @return A hash code for this object. */ public int hashCode() { return book.hashCode(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -