My goal is to have a list of cars as an Object so that, I can retrieve a Car from that list. As well as get details of the cars. Can someone point me to the right direction
What I have done so far.
- Create a class called Car and have the variables CarNum, carName, carPlate;
- generated getters and setters for the variables and a toString as the carName
- Create a class called CarCollection as follows
.
public class CarCollection {
private List<CarItem> mCarList;
public void addVan(CarItem v) {
mCarList.add(v);
}
public List<CarItem> getCarList() {
return mCarList;
}
The following test doesn't work. Why?
public class TestCarCollectionprocess {
public static void main(String[] args) {
CarItem car1 = new CarItem();
car1.setmCarName("Pedro");
car1.setmCarNum(1);
CarItem car2 = new CarItem();
car2.setmCarName("Rene");
car2.setmCarNum(2);
CarCollection carList = new CarCollection();
carList.addCar(car1);
carList.addCar(car2);
System.out.println(carList.getCarList());
}
}