CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    Perth, Australia
    Posts
    1

    Elevator assignment

    I hope someone can shed light on my problem !
    I am a frustrated beginner, trying to complete the Deitel and Deitel assignment for an Elevator Simulation. I am aiming low, at just 2 floors and a sinlge person, but have great trouble getting calls to methods of other classes working.
    If I want a method of Class B to recognize an object from Class A, I assume I would pass the object from Class A as an argument to a method in Class B, and then refer to it, but can't seem to get it to work.
    Any hints ?? They would be VERY appreciated.
    my private email is [email protected]
    Regards
    Scott




  2. #2
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    Re: Elevator assignment

    Scott W,

    I'm not 100% sure what the problem is but here is
    my solution to what I think you are talking about:// ClassA
    public class ClassA
    {
    // the object ClassB should recognize
    java.awt.Rectangle rect = new java.awt.Rectangle();
    // the instance of ClassB
    ClassB class_B = new ClassB();
    // the method to call, which in turn calls
    // ClassB's method
    public void callClassB()
    {
    classB.doSomething(rect);
    }
    }

    // ClassB
    public class ClassB
    {
    // the constructor... don't worry about this
    public ClassB()
    {
    }

    // the method ClassA will call...
    public void doSomething(java.awt.Rectangle rect)
    {
    // do something with the Rectangle...
    System.out.println(rect.toString());
    }
    }

    As you can see, ClassA instanciates ClassB, then calls ClassB's doSomething() method, passing a Rectangle object.

    This might not answer your question. So if there is a more specific problem you need solved, respond with more details.

    Regards,
    dogBear


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured