📄 orderitem.java
字号:
import com.sun.org.apache.regexp.internal.recompile;
public class OrderItem {
private Product product;// This instance variable represents the one-way association between OrderItem and Product. It contains a reference to a Product object.
private int quantity; //The quantity of the product in the order.
public OrderItem(){}
public OrderItem(Product initialProduct,
int initialQuantity){
this.product = initialProduct;
this.quantity = initialQuantity;
}
public Product getProduct(){
return this.product;
}//. Returns the value of the instance variable product, a reference to a Product object.
public int getQuantity(){
return this.quantity;
}//. Returns the value of the instance variable quantity.
public void setQuantity(int newQuantity){
this.quantity = newQuantity;
}//. Sets the instance variable quantity to the value of parameter newQuantity.
public double getValue(){
return this.quantity*this.product.getPrice();
}//. Returns the product of quantity and price.
public String toString(){
return this.getQuantity()+" "+
this.product.getCode()+" "+
this.product.getPrice();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -