• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding objects to an array from an implemented class  RSS feed

 
Macy Sempre
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my apologies if this question is complex/confusing. I am in an intro java course and I am having some difficulties with one of my assignments!
This assignment is to create specifications for some shapes (rectangles and triangles), but it must be implemeneted as such:
All shapes must implement a calculated interface which calculates their area/perimeter. A shapemanger class stores the calculated shapes in an array capable of storing up to 10 objects...


THE CODE:


Currently my output is:

The Area of the rectangle = 0 The Perimeter of the rectangle =0

I am really stuck on what I am doing wrong, and why the output isnt calculated properly. Any assistance on this is really appreciated, thank you very much for your help and your patience!
 
Macy Sempre
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone? Anyone?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at your constructor:


Can you tell us, in English, exactly what you think this does? Or even just the first line?

Or, simply this: When we do X = Y, what happens? What gets changed?
 
Macy Sempre
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply...

it constructs a rectangle object which takes four parameters of type int

what I would like it to do is take the variables passed to that object in the main and apply them to the methods declared below the constructor...
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Macy Sempre wrote:thanks for the reply...

it constructs a rectangle object which takes four parameters of type int


I know at a high level what you think it does.

I'm asking you to look at simply X = Y and tell me what you think that does. I'm trying to get you to pay closer attention to your code so that you can see your error, and I also want to see if you understand variable assignment correctly, so I can tell if your error was simply a typo, or indicative of a misunderstanding of a language fundamental.
 
Macy Sempre
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah.. i flip flopped my variable declarations... maybe should have come up with a different naming convention, thanks!
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Macy Sempre wrote:ah.. i flip flopped my variable declarations...


Assignments, not declarations. A declaration is where you state the type and name of a variable.

maybe should have come up with a different naming convention,

The usual approach is to use the same name, but use the this qualifier for the member variables.



thanks!


You're welcome! Good job taking the clues and hunting it down!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!