I did search on internet, but still don't understand, so I ask this question here.
in the small program below, I created two tour instance, all I want to do is putting tour[2] in without changing "Tour tour[]=new Tour[2];".
A lot of people recommend ArrayList, but I don't know how to do it in this code.
class Test{
public static void main(String args[]){
class Tour{
private String tourId;
private String tourDescription;
private double tourFee;
private int numOfBooking;
public Tour(String tourId,String tourDescription,double tourFee){
this.tourId=tourId;
this.tourDescription=tourDescription;
this.tourFee=tourFee;
}
public void print(){
System.out.println("ID:"+this.tourId);
System.out.println("Desc:"+this.tourDescription);
System.out.println("Fee:"+this.tourFee);
}
}
Tour tour[]=new Tour[2];
tour[0]=new Tour("AB001","TOUR1",100);
tour[1]=new Tour("AB002","TOUR2",200);
}
}