menuitem.java

来自「深入浅出设计模式书中的源代码」· Java 代码 · 共 48 行

JAVA
48
字号
package headfirst.composite.menu;import java.util.Iterator;import java.util.ArrayList;public class MenuItem extends MenuComponent {	String name;	String description;	boolean vegetarian;	double price;    	public MenuItem(String name, 	                String description, 	                boolean vegetarian, 	                double price) 	{ 		this.name = name;		this.description = description;		this.vegetarian = vegetarian;		this.price = price;	}  	public String getName() {		return name;	}  	public String getDescription() {		return description;	}  	public double getPrice() {		return price;	}  	public boolean isVegetarian() {		return vegetarian;	}  	public void print() {		System.out.print("  " + getName());		if (isVegetarian()) {			System.out.print("(v)");		}		System.out.println(", " + getPrice());		System.out.println("     -- " + getDescription());	}}

⌨️ 快捷键说明

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