📄 exercise 3.product.java
字号:
/**
* This class models a generic product in the store.
*
* @author Neil
* @version 1.0.0
*/
public class Product {
protected String code;
protected String description;
protected double price;
/**
* Getter of the property <tt>code</tt>
*
* @return Returns the code.
*/
public String getCode() {
return code;
}
/**
* Getter of the property <tt>description</tt>
*
* @return Returns the description.
*/
public String getDescription() {
return description;
}
/**
* Getter of the property <tt>price</tt>
*
* @return Returns the price.
*/
public double getPrice() {
return price;
}
/**
* Constructor that initializes the instance variables code, description,
* and price.
*
* @param initialCode
* @param initialDescription
* @param initialPrice
*/
public Product(String initialCode, String initialDescription,
double initialPrice) {
code = initialCode;
description = initialDescription;
price = initialPrice;
}
/**
* Overrides the method equals in the class Object. Two Product objects are
* equal if their codes are equal.
*
* @param product
* @return Return <tt>true</tt> if the codes are equal. Return
* <tt>false</tt> if the codes are not equal.
*/
public boolean equals(Product product) {
if (code == product.getCode())
return true;
return false;
}
/**
* Overrides the method toString in the class Object. Returns the string
* representation of a Product object.
*
* @return Returns the string representation of a Product object like
* <tt>code_description_price</tt>.
*/
public String toString() {
return code + "_" + description + "_" + price;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -