OOP Using Python Hands-On Assessment
OOP Using Python Hands-On Assessment
COPYRIGHT NOTICE
© 2017 Infosys Limited, Bangalore, India. All Rights Reserved.
Infosys believes the information in this document is accurate as of its publication date;
such information is subject to change without notice. Infosys acknowledges the
proprietary rights of other companies to the trademarks, product names and such other
intellectual property rights mentioned in this document. Except as expressly permitted,
neither this documentation nor any part of it may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, electronic, mechanical, printing,
photocopying, recording or otherwise, without the prior permission of Infosys Limited
and/ or any named intellectual property rights holders under this document.
Instructions to Candidates:
1. Follow the class diagram strictly. Read the problem statement, functionality and the other
details provided carefully and implement the solution
2. Ensure that all the constructors are public and DO NOT change the prototype of the
constructor and the methods
3. Code submitted with compilation errors may not get evaluated
4. The coding standards are mandatory wherever applicable
Guidelines:
1. This assessment is intended to test the hands on skills related to Programming and Database
Connectivity using Python
2. You must use Eclipse for implementing
NOTE: NOT adhering to the above instructions and guidelines may lead to drastic reduction in your score
even if the code is executing without any errors
Employees
Consultants
Project Manager
Class Diagram
Note:
Implementation Details:
Class: Salary
Salary
__basicpay
calculatesalary()
Add code to Salary based on the class diagram. Wherever needed, the additional implementation details
are given below.
Declare the member variable basicpay, initialize the variable with value 5000.
Class: Employee
Employee
__employeeid
__employeename
__typeofemployee
__telephoneno
__skillset
__status
counter : static
Employee
(employeename,typeofemployee,telephoneno,skillset)
getemployee()
getemployeename()
gettypeofemployee()
gettelephoneno()
getskillset()
getstatus()
validatetelephoneno()
Python Hands-On Assessment
Add code to Employee based on the class diagram and the additional implementation details are given
below.
Constructor
It initializes employeename, typeofemployee (‘P’ for Permanent Employee, ‘C’ for Consultant),
telephoneno, skillset and auto generates employeeid.
employeeid should an integer value starting from 1000. For example first employeeid would be
1000; the second would be 1001 etc. Use the counter variable appropriately for auto-generation
logic
validatetelephoneno()
• This method validates the telephoneno member variable and returns a boolean value
• telephoneno should begin with the digit 1 and should be of 10 digits only
• This method returns true if the value of telephoneno is valid, otherwise it must return false
Class: PermanentEmployee
PermanentEmployee
__yearsofexperience
__allowance
__salary
PermanentEmployee(employeename,typeofemployee
,telephoneno,skillset,yearsofexperience)
validatetypeofemployee()
calculatesalary()
Add code to PermanentEmployee based on the class diagram and the additional implementation details
are given below.
Python Hands-On Assessment
Constructor
It initializes yearsofexperience and calls the base class constructor by passing employeename,
typeofemployee, telephoneno and skillset.
validatetypeofemployee ()
Valid values of typeofemployee is ‘P’ or ‘p’ (P indicates Permanent employee).
This method must check whether typeofemployee is valid. If so, it must return true
Otherwise it return false.
calculatesalary()
o This method calculates salary for permanent employees based on the below logic and returns a
double value
o It validates telephoneno and typeofemployee by invoking validatetelephoneno() and
validatetypeofemployee()
o If any of the validate methods return false, display an appropriate error messages
o If all the above validate methods return true –
It calculates the allowance based on the yearsofexperience. Use Table 1 below to compute the
appropriate values
Table 1
yearsofexperience allowance
Greater than or equal to 15 20% of basicpay
Greater than or equal to 10 10% of basicpay
and less than 15
Greater than or equal to 5 5% of basicpay
and less than 10
Class: Consultant
Consultant
__noofhours
Python Hands-On Assessment
__payrateperhour
__consultantfee
Consultant(employeename,typeofemployee,tele
phoneno,skillset,noofhours)
calculatesalary()
Add code to Consultant based on the class diagram and the additional implementation details are given
below.
Constructor
o It sets the value of noofhours and calls the base class constructor by passing
employeename, typeofemployee, telephoneno and skillset.
calculatesalary()
o This method calculates salary for consultants based on the below logic and returns a double value
o it validates telephoneno by invoking validatetelephoneno()
o checks if the typeofemployee is consultant only
o checks if the consultant skills are either jee or ms (microsoft)
o if any of the validate methods return false, display an appropriate error messages
o if all the above validate methods return true –
It calculates the payrateperhour based on the skillset. Use Table 2 below to compute the
appropriate values
Table 2
Skills payRatePerHour
JEE Rs. 500
MS Rs. 350
Otherwise Rs. 250
Python Hands-On Assessment
Class: Project
Project
__projectid
__employee Employee
counter :static
Project()
allocateproject(Employee)
Add code to Project based on the class diagram and the additional implementation details are given
below.
Constructor
allocateproject(employee)
o This method checks whether an employee is eligible for a Project by passing an employee object
based on the below logic and returns a String value
o Initialize employee object
o Declare a local variable called eligible as string
o Checks if the typeofemployee is either Permanent Employee or Consultant
o Checks if the skills of the employee is in projecttechnology by iterating through the loop
o consultant skills are either JEE or MS (Microsoft)
o If any of the above conditions are not satisfied (false), set eligible with an appropriate error
messages
o If all the above conditions are true –
o Set eligible as "You are allocated to Project Id: " and display projectid
o projectid should be auto generated by appending the letter “P” and incrementing the
counter variable starting 5000
For example: P5000, P5001 etc. should be displayed if employees satisfies the above
condition
Python Hands-On Assessment
Starter Code:
print("Salary:", e1.calculatesalary())
print("Salary:", e2.calculatesalary());
print("Salary:", e3.calculatesalary());
print("Employee number:",c1.getemployeeId());
print("Salary:",c1.caculatesalary());
print("Salary:", c2.caculatesalary());
p = Project ();
Python Hands-On Assessment
p1 = Project ()
p2 = Project();