( ) {rentaBike = new ArrayListRentABike("Bruce's Bikes"); }
public void setRentABike(RentABike rentABike){
this.rentABike = rentABike;
}
public void printAllBikes( ) {
System.out.println(rentaBike.toString( ));
Iterator iter = rentaBike.getBikes().iterator( );
while(iter.hasNext( )) {
Bike bike = (Bike)iter.next( );
System.out.println(bike.toString( ));
}
}
public static final void main(String[] args) {
CommandLineView clv = new CommandLineView( );
clv.printAllBikes( );
}
}
接下来是服务,即模型。它是一种带有数组表的简单实现。它对模型(RentaBike)具有依赖性。 interface RentABike {
List getBikes( );
Bike getBike(String serialNo);
}
public class ArrayListRentABike implements RentABike {
private String storeName;
final List bikes = new ArrayList();
public ArrayListRentABike(String storeName) {
this.storeName = storeName;
bikes.add(new Bike("Shimano", " Roadmaster", 20, "11111", 15, "Fair"));
bikes.add(new Bike("Cannondale", "F2000 XTR", 18, "22222",12,"Excellent"));
bikes.add(new Bike("Trek","6000", 19, "33333", 12.4, "Fair"));
}
public String toString() { return "RentABike: " + storeName; }
pub上一页 [1] [2] [3] [4] [5] [6] 下一页
|