FileDocCategorySizeDatePackage
ArrayListRentABike.javaAPI DocExample1101Fri Apr 22 11:18:34 BST 2005com.springbook

ArrayListRentABike.java

package com.springbook;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

public class ArrayListRentABike implements RentABike {
   private String storeName;
   final List bikes = new ArrayList();

   public void setStoreName(String name) {
      this.storeName = name;
   }

   public String getStoreName() {
      return storeName;
   }

   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 "com.springbook.RentABike: " + storeName; }

   public List getBikes() { return bikes; }

   public Bike getBike(String serialNo) {
      Iterator iter = bikes.iterator();
      while(iter.hasNext()) {
         Bike bike = (Bike)iter.next();
         if(serialNo.equals(bike.getSerialNo())) return bike;

      }

      return null;
   }
}