orderitem.java

来自「ssd3 java程序练习 exercise 3 绝对没有问题」· Java 代码 · 共 39 行

JAVA
39
字号
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 + =
减小字号Ctrl + -
显示快捷键?