• Post Reply Bookmark Topic Watch Topic
  • New Topic

User Inputting Objects into ArrayLists  RSS feed

 
Harrison McDonald
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm new to java and up until now whenever I have created an object it has been via the BlueJ interface. I would make an object manually and then manipulate it with my methods.

I have made a basic program which adds objects into arraylists via the BlueJ interface. However I now need to prompt a user to enter a string which should create the specific object and add to its ArrayList.

Is there a way to create objects without manual specifying the parameters? I can provide some of my code if it is needed I am trying to make a crude version of Plant vs Zombies for an assignment.
I am aware of the scanner class but I only know how to prompt a user but I feel like if I can figure a way to create the objects I can dynamically I can associate the string inputs to the proper arraylists.

Thanks


 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I personally dislike BlueJ.

I think you have several problems and I don't know how much you know about each of them. I presume you know how to declare and initialise a ListYou can read about Lists and about generics in the Java Tutorials: One section. A section about generics: note there are two generics sections.
Adding to a List is simple: remember Lists default to adding elements at their “end”Since both those things seem simple, are you having difficulties creating objects, or getting String input from the keyboard?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!