WEB开发网
开发学院软件开发Java hand first 设计模式 -迭代器模式 阅读

hand first 设计模式 -迭代器模式

 2009-09-17 00:00:00 来源:WEB开发网   
核心提示: B食物 Java代码publicclassBFood{privateStringname;privatedoubleprice;privatebooleanisVaggltable;publicBFood(Stringname,doubleprice,booleanisVaggltable){t

B食物

Java代码   

public class BFood { 
 private String name; 
 
 private double price; 
 
 private boolean isVaggltable; 
 
 public BFood(String name, double price, boolean isVaggltable) { 
 this.name = name; 
 this.price = price; 
 this.isVaggltable = isVaggltable; 
 } 
 
 public String getName() { 
 return name; 
 } 
 
 public void setName(String name) { 
 this.name = name; 
 } 
 
 public double getPrice() { 
 return price; 
 } 
 
 public void setPrice(double price) { 
 this.price = price; 
 } 
 
 public boolean isVaggltable() { 
 return isVaggltable; 
 } 
 
 public void setVaggltable(boolean isVaggltable) { 
 this.isVaggltable = isVaggltable; 
 } 
 
 @Override 
 public String toString() { 
 // TODO Auto-generated method stub 
 return "Name:" + name + " Price:" + price + " isVaggltable:" 
  + isVaggltable; 
 } 
 
}

B菜单

Java代码   

public class BMenu implements Menu { 
 
 //利用数组封装 
     private static BFood[] BFoodArray = null; 
 
 static { 
 BFoodArray = new BFood[] { new BFood("1bfood", 63, true), 
  new BFood("2bfood", 36, true), new BFood("3bfood", 25, false) }; 
 } 
 
 @Override 
 public Iterator createIterator() { 
 // TODO Auto-generated method stub 
 ArrayIterator<BFood> ai = new ArrayIterator<BFood>(BFoodArray); 
 return ai; 
 } 
 
}

Tags:hand first 设计模式

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接