Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
Like Tree1Likes

Thread: Help with multiple classes

  1. #21
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: Help with multiple classes

    Are you talking about this block of code from the tester
    Java Code:
    for (int radius = 1; radius < 5; ++radius)
    		for (int height = 1; height < 5; ++height) {
    			if (radius == height)
    				spheres.add(new Sphere(radius));
    			if (radius > height)
    				cones.add(new Cone(radius, height));
    			if (radius + height == 6)
    				cylinders.add(new Cylinder(radius, height));
    		}
    ??
    I would assume the data there is well, from the for loop...Yes?
    Aside from radius and height I don't think it needs anything else =/

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default Re: Help with multiple classes

    Look at only the code for the Sphere class!!!

    What data is in an instance of an object. If you create a Sphere object, what data does it have it in?
    Does it need anything more to compute its volume?

    When you create an instance of the Sphere class, what data is given to the constructor?

  3. #23
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: Help with multiple classes

    Sorry, my mind is sort of shutting down...too much programming and calculus. Let me think about that for a while and get back to you.

  4. #24
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: Help with multiple classes

    Okay, by data are you talking about my private radius variable that was initialized to 0? If not, I do not know what you mean.

  5. #25
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default Re: Help with multiple classes

    What more do you need than the radius to compute the volume?
    Does the Sphere class object get its radius when it is created?

  6. #26
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: Help with multiple classes

    Nothing. A radius of type double is the only parameter in the getVolume method.
    And I am not sure if it got its radius when created...should I still be looking in the sphere class, or the test class now?

  7. #27
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default Re: Help with multiple classes

    Your problem was in creating and using the getVolume() method.
    Does it need any parameters or does the Sphere object contain all the data needed to compute the volume?
    Aimforthehead likes this.

  8. #28
    Aimforthehead is offline Member
    Join Date
    Sep 2011
    Posts
    45
    Rep Power
    0

    Default Re: Help with multiple classes

    ..........(moment of enlightenment)
    I understand now...I should not have put in parameters for getVolume or getSurfaceArea. I think my program works now, if I have any issues I'll be posting them on this thread. Thanks for all your time and patience helping me understand this!

  9. #29
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default Re: Help with multiple classes

    Glad you got it.
    Come on back anytime.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Multiple classes error
    By nat45928 in forum New To Java
    Replies: 0
    Last Post: 05-09-2011, 02:10 AM
  2. Multiple images from different classes
    By superbriggs in forum Java 2D
    Replies: 1
    Last Post: 03-20-2011, 08:59 AM
  3. Multiple classes
    By Lund01 in forum New To Java
    Replies: 1
    Last Post: 03-16-2011, 02:58 PM
  4. help with GUI and multiple classes
    By sssss in forum Advanced Java
    Replies: 14
    Last Post: 01-16-2011, 10:08 PM
  5. Help with multiple frames/classes
    By Celletti in forum AWT / Swing
    Replies: 1
    Last Post: 04-28-2010, 03:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •