⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goods.java

📁 java装饰模式。通过装饰完成对上层类的封装。
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -