public boolean writeToFile(String filename)
    {
        /* instantiate PrintWriter ofile1 as null, and call getSize() to obtain current
         * number of HousePets in hpArray (to be used for FOR loop iteration limit) */
        PrintWriter ofile1 = null;
        int listSize = getSize();
        boolean hasBeenWritten = false;
        
        /* try to create a new PrintWriter using user-provided filename */
        try
        {
            ofile1 = new PrintWriter(new File(filename));
        }
        catch(FileNotFoundException e)
        {
            System.out.println("Error: Unable to open destination file " + filename +
                " " + e);
            hasBeenWritten = false;
        }
        
        /* if PrintWriter ofile1 was created successfully, iterate over FOR loop, calling
         * HousePet.writeToFile() on each HousePet in the list.
         * Note: could alternatively put all of the code that is in the "IF" below
         * into the try block under line with PrintWriter assignment as ofile1 */
        if(!ofile1.equals(null))
        {
            for(int i = 0; i < listSize; i++)
            {
                /* call HousePet.writeToFile() to write the attributes of current
                 * HousePet to the file then write separator "****\n" */
                hpList[i].writeToFile(ofile1);
                ofile1.println("****");
                
            }//end of FOR loop
            
            hasBeenWritten = true;
        }
        
        if(hasBeenWritten == true)
        {
            hasBeenSaved = true;
        }
        
        /* close PrintWriter ofile1: "flush the output buffer" */
        ofile1.close();
        
        return hasBeenWritten;
        
    }//end writeToFile()