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 2 of 2

Thread: Trouble with using Enumeration and Inheritance in Abstract Classes

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trouble with using Enumeration and Inheritance in Abstract Classes

    I have a assignment that I am having trouble with. I need to create a abstract class Person with subclasses Student, Employee, Staff, and Faculty. The problem I am running into involves the Staff and Faculty classes. Here is the parts of the UML diagram that we have to follow for the assignment, there are more classes but I pretty sure that I have completed those correctly.

    Create the class structure represented in the UML diagrams below. When finished, zip all necessary source (.java) files into a single archive named with your last name and submit it along with one printed copy of each file.
    For all constructors, parameters are in order of declaration (ie. name, address, phone, email, ). The class Date is provided as discussed in class.

    Faculty
    - officeHours : String
    - rank : Rank

    + Faculty()
    + Faculty(String,String,String,String,String,int,int ,int,int,String,Rank);
    + getOfficeHours() : String
    + getRank() : Rank
    + setOfficeHours(String) : void
    + setRank(Rank) : void
    + toString() : String

    ≪enumeration≫
    Rank
    - Adjunct
    - Instructor
    - AssocProf
    - AsstProf
    - Professor

    My code for the class Faculty:

    class Faculty extends Employee{
    enum Rank{Adjunct, Instructor, AssocProf, AsstProf, Professor};
    private String officeHours;
    private Rank rank;

    public Faculty(){
    officeHours = "";
    }
    public Faculty(String n, String a, String p, String e, String o, int s, int m, int d, int y, String h, Rank r){
    super(n,a,p,e,o,s,m,d,y);
    officeHours = h;
    rank = r;
    }
    public String getOfficeHours(){
    return officeHours;
    }
    public Rank getRank(){
    return rank;
    }
    public void setOfficeHours(String h){
    officeHours = h;
    }
    public void setRank(Rank r){
    rank = r;
    }
    public String toString(){
    return super.toString() + " Office Hours: " + officeHours + " Rank: " + rank;
    }
    }

    Staff
    - title : Title

    + Staff()
    + Staff(String,String,String,String,String,int,int,i nt,int,Title);
    + getTitle() : Title
    + setTitle(Title) : void
    + toString() : String
    ≪enumeration≫
    Title
    - Clerical
    - Maintenance
    - Supervisor
    - Administrator

    My code for the class Staff:

    class Staff extends Employee{
    enum Title {Clerical, Maintenance, Supervisor, Administrator};
    private Title title;

    public Staff(){

    }
    public Staff(String n, String a, String p, String e, String o, int s, int m, int d, int y, Title t){
    super(n,a,p,e,o,s,m,d,y);
    title = t;
    }
    public Title getTitle(){
    return title;
    }
    public void setTitle(Title t){
    title = t;
    }
    public String toString(){
    return super.toString() + " Employee Title: " + title;
    }
    }

    The problem I am running into involves the enumeration for Title and Rank. I'm pretty sure that I have used enumeration right but when I try an test it in the main program I get 4 errors (Cannot Find Symbol). The statements that are causing the errors are listed below.
    error: cannot find symbol
    Staff s1 = new Staff("John Doe", "5 Main St.", "123-450-6789","jd@abc.edu", "", 29000, 2, 5, 1983, Title.Clerical);
    ^
    symbol: variable Title
    location: class TestPerson

    error: cannot find symbol
    Faculty f1 = new Faculty("John Doe", "5 Main St.", "123-450-6789","jd@abc.edu", "", 29000, 2, 5, 1983, "", "10 to 12", Rank.Professor);
    ^
    symbol: variable Rank
    location: class TestPerson

    error: cannot find symbol
    System.out.println(f1.getName() + " is a" + f1.getTitle() + "his office hours are:" + f1.getOfficeHours());
    ^
    symbol: method getTitle()
    location: variable f1 of type Faculty

    error: cannot find symbol
    f3.setTitle(Rank.Instructor);
    ^
    symbol: variable Rank
    location: class TestPerson

    I'm not sure if there is a problem with the main program or if I need to change something in the Staff and Faculty classes. If anyone could help me out with this problem it would be greatly appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,949
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: Trouble with using Enumeration and Inheritance in Abstract Classes

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    If you wrap the error messages that contain the ^ in code tags when its pasted here, the position of the ^ will be preserved.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Abstract Classes?
    By jean28 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 26th, 2013, 07:13 AM
  2. Replies: 17
    Last Post: July 27th, 2012, 01:52 AM
  3. New Programming Student, Having Trouble With Abstract Classes/Interfaces
    By bulx0001 in forum Object Oriented Programming
    Replies: 2
    Last Post: February 10th, 2012, 07:24 AM
  4. Multilevel inheritance of an abstract class
    By user2205 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 27th, 2011, 06:00 PM
  5. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 07:15 AM