Learning Java

Hi I was trying to make a arraylist of objects and add more with data via argument to the constructor to make objects. Here is part of my code, wondering if anybody could give me some insite?

ArrayList purchase = new ArrayList();
String answer;
System.out.print("Please enter the price or enter -1 to quit");
price=in.nextDouble();
if (price!=-1){
System.out.print("Is this purchase a pet Y/N");
answer= in.nextLine();
if (answer.equals("Y")){
answer1=true;
}
purchase.add(new Item(price,answer1));

Specify the type of item being placed in the array list.

ArrayList purchase = new ArrayList();

Hey
Could you please provide some more details? What's not working?

I don´t know how the Item class looks like, but I think that you should use diamond operators on your arraylist. Are you using them or does the forum just hide them from your post?

ArrayList<Item> purchase = new ArayList<Item>();
1 Like

Thanks guys but this was only part of my code, I got it to work, turned out I needed to reference each index of object to something else to use a method on it, I got to kind of work, just needs a little more work to get going.

lol object arraylists are strange