0

how do I print all elements in an ArrayList??
this my code below.

import java.util.ArrayList;
/**
 * Write a description of class PetDatabase here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PetDatabase
{
    private String name;
    private String species;
    private int insurance;
    private ArrayList<Pets>pets;

    public PetDatabase()
    {
        pets = new ArrayList<Pets>();
    }

    public int Size()
    {
       return pets.size();
    }

    public void petRecord(String name,String species,int insurance)
    { 
       Pets can = new Pets();
       can.getName(name);
       can.getSpecies(species);
       can.getInsurance(insurance);
       pets.add(can);
    }
    public void PrintAll()
    {


    }
    }

Edited by peter_budo: Code formatting

3
Contributors
2
Replies
16
Views
2 Years
Discussion Span
Last Post by stultuske
1

and, to avoid getting 'weird' results, don't forget to override the toString method in your Pet class.

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.