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

📄 test.java

📁 java装饰模式。通过装饰完成对上层类的封装。
💻 JAVA
字号:
import java.io.*;
import java.util.*;
public class test
{
	public static void main(String[] args)
	{

		String customerName;
		String marketName;

		Scanner in =new Scanner(System.in);
		System.out.println("enter your name!\n");
		customerName=in.nextLine();
		System.out.println("enter the market name");
		marketName=in.nextLine();

		abs theAbs=new head(customerName,marketName);
		theAbs =new body(theAbs);

		System.out.println("Assume that you buy 3 food which is 4 dollars each,\n");
		System.out.println("and then you buy 5 clothes which is 20 dollars each\n");

		theAbs=new food(4.0,3,theAbs);
		theAbs=new clothes(20.0,5,theAbs);

		theAbs=new tail(theAbs);
		theAbs.display();

		System.out.println("\n\n\nAssume you buy something else in another way\n");

		abs another=new anotherHead();
		another=new body(another);

		System.out.println("Assume that you buy 5 food which is 10 dollars each,\n");
		System.out.println("and then you buy 3 clothes which is 15 dollars each\n");

		another=new food(10.0,5,another);
		another=new clothes(15.0,3,another);

		another=new anotherTail(another);
		another.display();

	}
}

⌨️ 快捷键说明

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