ArrayList: trouble with the cast operator using the get method

I'm using a sample code example to ask my question. I'm building an ArrayList of Cars and each car has a name(string) and a number(int). I having trouble with the cast operator using the get method. Errors of type; cannot convert primitive int, or I see a listing of memory referrences to each car in the list.  
public class Cars
{
  ArrayList<Car> CarAttributes = new ArrayList<Car>();
  public static void main(String[] args)
  {
    .....
    System.exit(0);
  }
	
  public void addCars(BufferedReader inFile)
  {
    //This method works fine
    //read in car name (string) and car number (int) and add to ArrayList
		
    CarAttributes.add( new Car(name, number));
 
    //After I add to the list 4 times
    System.out.println(Car.size()); //works fine and displays 4
  }
 
  public void displayCars()
  {
    // this is were I'm have trouble
    // I need to pull in each car attribute (name:string, number(int) to display and/or manipulate
    // I've tried many things, but with either, error cannot convert primitive int, or 
    // a listing of memory referrences to each car in the list 
	
    }
}
 
public class Car
{
	private String carName;	
	private int carNumber
	
	public Car(String cName, int cNumber)
	{
		// Constructor
		this.setCarName(cName);
		this.setCarNumber(cNumber);
		// End Constructor
	}		
	
	public String getCName()
	{
		return this.carName;
	}
	
	public int getCNumber()
	{
		return this.cNumber;
	}
	
	public void setCarName(String cName)
	{
		this.carName = cName;
	}
	
	public void setCarNumber(int cNumber)
	{
		this.carNumber = cNumber;
	}
}

Open in new window

EnviewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
You can 'get' all cars by:

    for(Car c : CarAttributes)
    {
         String name = c.getCName();
         int number = c.getCNumber();
    }


;JOOP!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EnviewAuthor Commented:
Your solution worked great! Thank You!
0
sciuriwareCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.