如何将其添加到数组列表中?

How can I add this to an arraylist?

我想将这些车辆添加到数组列表中,但必须通过 CourierManagementSystemImpl class 中的 addVehicle 方法来完成。我不知道该怎么做。

部分 public class CMSTestHarness:

//Arraylist
ArrayList<Vehicle> vehicles = new ArrayList<Vehicle>(); 

// Van(registrationNo, make, model, year, odometer, serviceInterval)
cms.addVehicle(new Van("v1", "Toyota", "Sienna", 1998, 0.0, 500.0));
cms.addVehicle(new Van("v2", "Volkswagen", "Routan S", 2009, 0.0, 1000.0));

CourierMangementSystemImpl 的一部分class

@Override
    public void addVehicle(Van van) {
        // TODO Auto-generated method stub
    }

例如"vehicles"是CMS对象的字段。将参数传递给方法 addVehicle。在这个例子中,为了简单起见,我使用了字符串对象而不是 Van 对象。

public static void main(String[] args) {
    CMS cms = new CMS();
    // * This is Van object.
    cms.addVehicle(new Van("v1", "Toyota", "Sienna", 1998, 0.0, 500.0));
    cms.addVehicle(new Van("v2", "Volkswagen", "Routan S", 2009, 0.0, 1000.0));
    for (String s : cms.getVehicles())
        System.out.println(s);
}

public class CMS {

    private ArrayList<String> vehicles = new ArrayList<String>();

    public ArrayList<String> getVehicles() {
        return this.vehicles;
    }

    public void addVehicle(String van) {
        vehicles.add(van);
    }

}