📄 exercise 3.orderitem.java
字号:
/**
* This class models an item in an order.
*
* @author Neil
* @version 1.0.0
* @see Product
*/
public class OrderItem {
private Product product;
private int quantity;
/**
* Constructor that initializes the instance variables product and quantity.
*
* @param initialProduct
* @param initialQuantity
*/
public OrderItem(Product initialProduct, int initialQuantity) {
product = initialProduct;
quantity = initialQuantity;
}
/**
* Getter of the property <tt>product</tt>
*
* @return Returns the product.
*
*/
public Product getProduct() {
return product;
}
/**
* Getter of the property <tt>quantity</tt>
*
* @return Returns the quantity.
*
*/
public int getQuantity() {
return quantity;
}
/**
* Setter of the property <tt>quantity</tt>
*
* @param quantity
* The quantity to set.
*
*/
public void setQuantity(int quantity) {
this.quantity = quantity;
}
/**
* Returns the product of quantity and price.
*
* @return Returns the product of quantity and price.
*/
public double getValue() {
return product.getPrice() * quantity;
}
/**
* Overrides the method toString in the class Object.
*
* @return Returns the string representation of an OrderItem object. The
* String representation has the following format:
* <tt>quantity product-code product-price</tt>
*/
public String toString() {
return quantity + " " + product.getCode() + " " + product.getPrice();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -