How to display counts of how many objects have been created using toString method?

Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

How to display counts of how many objects have been created using toString method?

Hello, I am trying to write a GUI program for my computer class which requires us to create a superclass containing basic data for creating lines, rectangles, and ovals, subclasses of that superclass which have methods specific to each, a class that draws a randomized amount of each shape (and also randomizes the color and whether or not it is filled in for rectangles and ovals), and finally one that ties it all together (the test class). Our teacher gave us code to start from, which contained the superclass and Line subclass. In it was included two toString methods, the main(supeclass) one being:

The first one has ellipses because he intended us to be able to figure it out, which I followed up by adding in "x2 = %d", so on and so forth. From what I understand, the toString in the superclass is just there to be there essentially, as it will get overridden by the subclasses. Beyond that, I have no idea of how I would go about making a count of how many of each shape appears. Here is the rest of my code in totality...

I am just seeking some direction or a push in the right direction, I don't want or expect you all to give me the answer, I know how programming experts feel about people just posting to do that. :] Please help any way you can, thank you!

PS: Everything else works like a charm, it's just figuring out how to get counts for how many objects are created.

Re: How to display counts of how many objects have been created using toString method

I thought about trying to do that, but I figured out the problem I was having. I was trying to use the class DrawPanel's toString method DIRECTLY instead of using the "panel" instantiation that I made in the main class...dumb mistake. I ended up just making getters for the array lengths for the each subclass and using those in the toString method. Thanks for the help though!