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.

Solved it.

showing how might benefit the next person who encounters this problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.