This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Vectors  RSS feed

 
Chris Roberts
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you create a vector that can hold shapes if Shape.java, Point.java, and Circle.java files are given. Shape.java extends object, Point.java
extends Shape.java, and Circle.java extends Point.java. From there creating instances of the Point and Circle class and store them in the vector. From there, how do I write a loop that will go through and output the name of each element in the created vector.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Welcome to JavaRanch!

This sounds like a homework assignment. Why don't you give it a try yourself, and then when (if) you get stuck, show us what you've got so far?

The whole "teach a man to fish" thing; you understand.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store any type of Object in a Vector, although I would recommend using an ArrayList instead of a Vector.

To add an object to a vector use the Vector class's add() method. Then you write a loop which calls the get() method for each object.

When you get this far, if you still have questions, please ask something more specific.

Please do not expect someone to write the code for what appears to be your assignment and hand it to you.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!