📄 orderitem.java
字号:
/**
* This class maintains the attributes and methods of the OrderItem.
*
* @author Luorenhu
* @version 1.0.0
*/
public class OrderItem
{
/* product */
private Product product;
/* quantity */
private int quantity;
/**
* Constructs an <code>Coffee</code> object.
*
* @param initialProduct a <code>Product</code> with the product of the order.
* @param initialQuantity a integer that with the quantity of the order.
*/
public OrderItem(Product initialProduct, int initialQuantity)
{
product = initialProduct;
quantity = initialQuantity;
}
/**
* Returns the product of the Order.
*
* @return product of the Order.
*/
public Product getProduct()
{
return product;
}
/**
* Returns the quantity of the Order.
*
* @return quantity of the Order.
*/
public int getQuantity()
{
return quantity;
}
/**
* Modifies the quantity of this order.
*
* @param newQuantity a integer with the new quantity of the order.
*/
public void setQuantity(int newQuantity)
{
quantity = newQuantity;
}
/**
* Returns the value of the Order.
*
* @return value of the Order.
*/
public double getValue()
{
return getProduct().getPrice() * (double)getQuantity();
}
/**
* Returns the string representation of this <code>OrderItem</code>
* object (overrides the {@link Object#toString()} method).
*
* @return the string representation of this <code>OrderItem</code>
* object.
*/
public String toString()
{
String message = getQuantity() + " " + getProduct().getCode() + " " + getProduct().getPrice();
return message;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -