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: The Employee class

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

    Default The Employee class

    It is a common practice that in a business place employees get salary raise based on different criteria such as the position of the employee, job performance, department budget, sales proportion (if the employee is directly involved in sales), etc. In this question, you are going to implement the salary raise scheme for a standard work place.
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Write an Employee class that describes an employee with employeeID, firstName, lastName, and salary fields.

    Also write a constructor in Employee class that initializes all data fields. Create three different subclasses from class Employee as follows:
    1)A Manager subclass that invokes super class’ constructor to initialize its fields and implements the raise method with a 10% increment to the original salary.

    2) A SalesAssociate subclass that invokes super class’ constructor to initialize its fields. It should have an extra data field for commission and the raise for a sales associate should be calculated by adding the base salary and the commission amount.

    3) A Secretary subclass that invokes super class’ constructor to initialize its fields and implements the raise method with a 5% increment to the original salary

    Write a driver class TestEmployee to create an array of three elements: one manager, one sales associate, and one secretary and initialize each with arbitrary initial values that you choose. Calculate the salary raise for each employee and display them in well formatted way to standard output (screen).

    Hint: Since we won’t know in advance how method raise() is to be implemented, you need to define raise() method as abstract in the Employee class.

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Please, help! Here's my code. Please , check if it satisfies the conditions above. I usually make a lot of mistakes. Thank you!!! Sorry for the format, I am new to this forum


     
    abstract class Employee 
    {
        protected int employeeID;
        protected String firstName;
        protected String lastName;
        protected double salary;
     
        public Employee(int employeeID, String firstName, String lastName,
        double salary) 
        {
            this.employeeID = employeeID;
            this.firstName = firstName; 
            this.lastName = lastName;
            this.salary = salary;
        }
     
        public abstract void raise();
    }
     
     
    class Manager extends Employee {
        public Manager(int employeeID, String firstName, String lastName,
        double salary)
        {
            super(employeeID, firstName, lastName, salary);
        }
     
        @Override
        public void raise() 
        {
            salary = 1.1 * salary;
        }
     
        @Override
        public String toString()
        {
            return "Manager [employeeID=" + employeeID + ", firstName=" + firstName
            + ", lastName=" + lastName + ", salary=" + salary + "]";
        }
    }
     
     
     
    class SalesAssociate extends Employee 
    {
        private double commission;
     
        public SalesAssociate(int employeeID, String firstName, String lastName,
        double salary, double commission) {
        super(employeeID, firstName, lastName, salary);
        this.commission = commission;
        }
     
        @Override
        public void raise() 
        {
            salary += commission;
        }
     
        @Override
        public String toString() 
        {
            return "SalesAssociate [commission=" + commission + ", employeeID="
                + employeeID + ", firstName=" + firstName + ", lastName="   
        + lastName + ", salary=" + salary + "]";
        }
    }
     
    class Secretary extends Employee
    {
        public Secretary(int employeeID, String firstName, String lastName,
        double salary)
        {
            super(employeeID, firstName, lastName, salary);
        }
     
        @Override
        public void raise() 
        {
            salary = 1.05 * salary;
        }
     
        @Override
        public String toString() 
        {
        return "Secretary [employeeID=" + employeeID + ", firstName="
            + firstName + ", lastName=" + lastName + ", salary=" + salary
            + "]";
        }
    }
     
    public class TestEmployee 
    {
        public static void main(String[] args) 
        {
            Employee e1 = new Manager(1, "Larry", "Paul", 99.99);
            Employee e2 = new SalesAssociate(2, "Mary", "Janice", 97.2, 0.55);
            Employee e3 = new Secretary(3, "Jay", "Peace", 88);
            Employee[] es = new Employee[] { e1, e2, e3 };
     
            for (Employee e : es) 
            {
                System.out.println("Before raise");
                System.out.println(e);      
                System.out.println("After raise");
                e.raise();
                System.out.println(e);
                System.out.println();
            }
        }
    }


  2. #2
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: The Employee class

    .

Similar Threads

  1. Employee Class Exercise... Code will not run!!!!
    By jbarcus81 in forum What's Wrong With My Code?
    Replies: 25
    Last Post: January 26th, 2012, 03:39 PM
  2. Employee class won't set salary and number values
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2012, 06:01 PM
  3. weekly hours for each employee
    By sircamolate in forum Collections and Generics
    Replies: 18
    Last Post: September 1st, 2011, 06:09 PM
  4. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM