Click to See Complete Forum and Search --> : Elevator assignment


Scott W
May 3rd, 2000, 09:10 AM
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 scotcara@aeon.net.au
Regards
Scott

dogbear
May 4th, 2000, 06:21 AM
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