Human Resources Database

Human Resources Database

 Python code:

Write   a   Python   program   that   contains   a   class   named   Employee.
You’re writing a new   Human   Resources   system   for  a university   that   keeps   track   of   people.
Implement   the  initializer  (the   __init__   method).   The   initializer   takes   in   four   (4)   arguments:
a   fullname (string),   year   of   hire   (int),   month   of   hire   (int),   and   day   of   hire   (int).
Set   the   instantiated   Employee’s values   to   these   arguments.
Many   languages   have   only   a   constructor,   Python   has   both   a   constructor and   initializer.

  1. Implement   the  printName  method.   There   are   no   arguments   here.
    This   method   should   be   print out   the   person’s   full   name.
    It   is   a   void   function,   in   that   it   does   not   return   anything.
    Only   prints the   name.
  1. Implement   the   getName   method.   There   are   no   arguments.
    This   method    RETURNS    the   name of   the   employee   as   a   string.
  1. Implement   the  setName  method.   This   takes   one   additional   argument   “name”,
    which   is   for   the new   name   you   want   to   set   for   the   person.
    This   method   replaces   the   current   person’s   name value   with   a   new   one.
  1. Implement   the   setStartdateString   method.   This   takes   one   argument,
    a   string   containing   the employees   start   date   in   the   format   “yyyymmdd”.
    This   method   will   parse   the   string,   convert each   number   to   an   int,   and
    then   set   the   corresponding   instance   variables   to   the   correct values
    (year   of   hire,   month   of   hire,   and   day   of   hire).
  1. Instantiate   two   new   instances   of   an   Employee   inside   your   main   function.
    Each   person   should have   a   different   name.   You   should   show   each   method   working.
    For   instance,   after instantiation call the printName() method then change the name and call it again, etc.
    Make   sure   that   your   programs   execute   properly   from   the   Linux   shell! 

Solution 

class Employee:

def __init__(self,f=””,m=0,y=0,d=0):

self.fullname=f

self.month=m

self.year=y

self.day=d

defgetName(self):

returnself.fullname

defprintName(self):

print(self.getName())

defsetName(self,name):

self.fullname=name

defsetStartdateString(self,string):

self.year=int(string[:4])

self.month=int(string[4:6])

self.day=int(string[6:8])

def main():

a=Employee(“Jane Duane”)

a.printName()

a.setName(“Changed Jane Duane”)

a.printName()

a.setStartdateString(“20171121”)

print(a.year, a.month, a.day)

a.setStartdateString(“20160425”)

print(a.year, a.month, a.day)

b=Employee(“John Doe”)

b.printName()

b.setName(“Changed John Doe”)

b.printName()

b.setStartdateString(“20160518”)

print(b.year, b.month, b.day)

b.setStartdateString(“20150210”)

print(b.year, b.month, b.day)

main()