product.java
来自「ssd2 exercise3 的题目和答案」· Java 代码 · 共 88 行
JAVA
88 行
public class Product
{
/* code */
private String code;
/* description */
private String description;
/* price */
private double price;
/**
* Constructs an <code>Product</code> object.
*
* @param initialCode a string with the code of the product.
* @param initialDescription a string that describes the product.
* @param initialPrice a double that represents the price of the product.
*/
public Product(String initialCode, String initialDescription, double initialPrice)
{
code = initialCode;
description = initialDescription;
price = initialPrice;
}
/**
* Returns the code of the product.
*
* @return code of the product.
*/
public String getCode()
{
return code;
}
/**
* Returns the description of the product.
*
* @return description of the product.
*/
public String getDescription()
{
return description;
}
/**
* Returns the price of the product.
*
* @return price of the product.
*/
public double getPrice()
{
return price;
}
/**
* Two <code>Product</code> objects are equal if their codes
* are equal (overrides the {@link Object#equals(Object)} method).
*
* @param object object with which this <code>Product</code>
* is to be compared.
* @return <code>true</code> if the argument is an
* <code>Product</code> object <i>and</i> the code of
* the argument is equal to the code of this
* <code>Product</code>; <code>false</code> otherwise.
*/
public boolean equals(Object object)
{
return (object instanceof Product) && getCode().equals(((Product)object).getCode());
}
/**
* Returns the string representation of this <code>Product</code>
* object (overrides the {@link Object#toString()} method).
*
* @return the string representation of this <code>Product</code>
* object.
*/
public String toString()
{
String message = getCode() + "_" + getDescription() + "_" + getPrice();
return message;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?