transfering data between classes


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: transfering data between classes

  1. #1
    Join Date
    Jul 2005
    Posts
    78

    transfering data between classes

    This is for an assignment. I have completed all other requirements except for this:

    I have four classes
    abstract class Employee
    class PartTimeEmployee extends Employee
    class FullTimeEmployee extends Employee
    class Manager extends FullTimeEmployee
    class Payment


    Payment contains the main method.

    Payment() creates an object array containing all the information about the employees. In my main method, i put this "Payment newPayment = new Payment();" in order to create my array of employees.

    The call the Payment() creates an array:
    static Employee[] listEmps = new Employee[10];

    and then populates it with employee data using the set methods defined in the employee classes. eg:

    listEmps[0] = new FullTimeEmployee(name, salary, ID.....);
    listEmps[1] = new Manager(...);
    listEmps[2] = new PartTimeEmployee(...);




    Is there a way that I can access and change the array created in Payment() from the Manager class? eg have a method in the Manager class that changes the employee's salary?

    I've read through my course notes and textbook and can't find what I'm after... That said, I'm probably being dopey and just missing it all

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    The easiest way I can think of is that the Manager class has a
    constructor/set -method that passes the pointer of the Payment object to
    the Manager object(s), that in turn keeps a copy of this pointer.
    Then you could either make the listEmps array public or have a getListEmps
    method in Payment.
    Last edited by sjalle; 07-18-2005 at 05:41 AM.
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    78
    arrgggghhhh!!!!

    Sorry. I had a brain fart, and wasn't reading/comphrending my notes properly.

    I wasn't calling the method properly in the first place.

    Remember kiddies ClassName.methodName("Parameters")

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    BRAIN FART !!! .... that was a new one !!!
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center