Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help with inheriting classes

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with inheriting classes

    So there are 2 parts to this and I've figured out the first part but the second part was a little confusing.
    Part1: Create a class called Person that has two subclasses Student and Employee. Make Faculty and Staff subclasses of Employee. A person has name and address. A student has GPA as a real number between 0.00 and 4.00. An employee has an office address and a salary. A faculty member has a rank. A staff member has a title. Create a toString method in each class that returns a description of the person, including the class name, the person's name and the values of all the other attributes of the object.

    Create a test class that includes an array of persons containing at least one person from each of the subclasses. Then print out all objects in a loop.

    Part2: Now, add an abstract class Role that has no members. There are two subclasses of Role called EmployeeRole and StudentRole. Use the bodies of Employee and Student for those, as these classes are no longer needed. The Person class will have a list of roles, and a method addRole(Role r). Make FacultyRole and StaffRole subclasses of EmployeeRole as before. Add an abstract getPay method to EmployeeRole, and getPay() methods to StaffRole and FacultyRole. Make sure you have toString methods in FacultyRole and StaffRole, and that they are appropriately changed.

    Change the tester to conform to the new requirements. You still need an array of persons, but you will need to add roles to each person. In addition to what you did in the previous homework, you should have at least one person who is both student and staff.

    I can't quite figure out what addRole is supposed to do and how you even implement the Person class now that you have no subclasses extending it. Any help figuring out how I would implement multiple roles into the same person would be appreciated.


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Help with inheriting classes

    Quote Originally Posted by Harlow777 View Post
    I can't quite figure out what addRole is supposed to do and how you even implement the Person class now that you have no subclasses extending it. Any help figuring out how I would implement multiple roles into the same person would be appreciated.
    The method addRole(Role r) is to add a role to the role list of a person. Each person has a list of roles.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with inheriting classes

    I really need to see how addRole is going to be constructed. I'm a little lost on how to implement it. I know you will need the list of roles and the method in person but I don't know if I need an actual list or not, and I don't know how you would make the program add the correct roles in the Test class or even how you would construct a person object with more than one role. I have a constructor in each class that specifies the parameters of a person of that class, it is a little restrictive but I don't know of any other way to do it, and this doesn't allow me to specify all the parameters needed for someone of class Student and Staff.

Similar Threads

  1. Inheriting Applet and paint() GUI Method Logic?
    By Jakesta42 in forum Object Oriented Programming
    Replies: 1
    Last Post: August 8th, 2011, 06:58 AM
  2. Need Help with using classes [HELP]
    By dragon40226 in forum Java Theory & Questions
    Replies: 4
    Last Post: May 19th, 2011, 01:59 PM
  3. Classes problem
    By Skyton in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2011, 03:26 PM
  4. i/o classes question
    By p0oint in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 28th, 2010, 04:04 PM
  5. [SOLVED] Java program using two classes
    By AZBOY2000 in forum Object Oriented Programming
    Replies: 7
    Last Post: April 21st, 2009, 06:55 AM

Tags for this Thread