Hello. Im new here. I have a question:

I have this copy constructor here:

/** Copy Constructor.
     * Since landscape is immutable in the scope of our project, you could
     *   do a simple reference copy for it.
     * However, Fish and Plants are mutable, so those lists must be copied 
     *   with a DEEP copy!
     * (In other words, each fish and each plant must be copied.)
    public Model(Model other) {

        landscape = other.landscape;

        fish = new ArrayList<Fish>();
        for (Fish f : other.fish) {
            fish.add(new Fish(f));

        plants = new ArrayList<Plant>();
        for (Plant p : other.plants){
            plants.add(new Plant(p));

I want to ask how do I implement this:

    /** Returns a COPY of the plants list.  Hint:  Use the ArrayList<Plant> 
     * copy constructor, or you will fail our tests! */ 
    public ArrayList<Plant> getPlants() {

        //HOW DO I COPY the plants list


Thank you for your help.

4 Years
Discussion Span
Last Post by stultuske
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.