goods.java

来自「java装饰模式。通过装饰完成对上层类的封装。」· Java 代码 · 共 50 行

JAVA
50
字号
import java.io.*;
public abstract class goods extends abs
{
	double cost;
	int num;
	abs theAbs;
	String item="goods";
	public goods(double cost,int num, abs theAbs)
	{
		setCost(cost);
		setNum(num);
		this.theAbs=theAbs;
	}
	/*print the cost of every thing you buy */
	public void display()
	{
		theAbs.display();
		System.out.println(getItem()+"          "+getCost()+"            "+getNum()+"              "+getAllCost());
	}
	/*some useful function but easy to understand*/
	public double getCost()
	{
		return cost;
	}
	public void setCost(double cost)
	{
		this.cost=cost;
	}
	public double getAllCost()
	{
		return num*cost;
	}
	public double getNum()
	{
		return num;
	}
	public void setNum(int num)
	{
		this.num=num;
	}
	/*return the addtion of the cost of this goods and the cost of something you have bought*/
	public double getFinalCost()
	{
		return theAbs.getFinalCost()+getAllCost();
	}
	public  String getItem()
	{
		return item;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?