Anda di halaman 1dari 10

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.

Education, Training and Assessment Department


Infosys Limited
Electronics City
Hosur Road
Bangalore – 561 229, India.

Tel: 91 80 852 0261-270


Fax: 91 80 852 0362
www.infosys.com
mailto:ETA@infosys.com
Python Hands-On Assessment

Object Oriented Programming using Python


Hands-On Assessment
Duration: 2 hours Max Mark: 40

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

Few errors which might result in mark reduction:

1. Infinite loops/infinite recursive calls in the code


2. Class diagram violation
3. Improper constructor prototype or definition

WISH YOU ALL THE BEST


Problem Description:
Employee Management System:
iNext Ltd, a product based company with more than 50000 employees, that provides product solutions
to large number of clients from different countries. It uses a software product to maintain their
employee’s information and their project allocation details. The application is used by the following user
groups:

 Employees
 Consultants
 Project Manager

Write a Python program to implement the class diagrams below.


Python Hands-On Assessment

Class Diagram

Note:

1. Use case insensitive String comparison wherever applicable.


2. Perform case sensitive character comparison wherever applicable.
3. Do not include any extra instance variables or member methods in the given classes.
4. Do typecasting wherever appropriate
5. The order of passing the values to the child class constructor would be member variables of parent
class followed by the child class
Python Hands-On Assessment

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

Note: basicpay is to be fetched from Salary class in Table 1.

 Salary is computed by adding allowance with basicpay.


 Salary is the return value.

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

__projecttechnology : list or tuple

counter :static

Project()

allocateproject(Employee)

Add code to Project based on the class diagram and the additional implementation details are given
below.

Constructor

o It initializes the value of projecttechnology as “JEE”, “MS”.

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

o The variable eligible is the return value from this method.

Starter Code:

 Read and understand the functionality of the code


 You can modify the below code for testing purpose but ensure that you are submitting it
compilation error free
 Starter code will not be evaluated

Follow Indentation while copying the below Starter code in Eclipse.

e1 = PermanentEmployee ("John", 'P', 1111111111L, "MS", 10)

print (“Employee number:", e1.getemployeeId())

print("Salary:", e1.calculatesalary())

e2 = PermanentEmployee("Mary",'p', 9999999999L, "MS", 5)

print("Employee number:", e2.getemployeeId());

print("Salary:", e2.calculatesalary());

e3 = PermanentEmployee("Veena",'c', 1999999999L, "MS", 5);

print("Employee number:", e3.getemployeeId());

print("Salary:", e3.calculatesalary());

c1 = Consultant("Joe", 'C', 1111111111L, "JEE", 12);

print("Employee number:",c1.getemployeeId());

print("Salary:",c1.caculatesalary());

c2 = Consultant("Tom", 'p', 1111111111L, "JEE", 12);

print("Employee number:", c2.getemployeeId());

print("Salary:", c2.caculatesalary());

p = Project ();
Python Hands-On Assessment

print("Project Id: ", p.allocateproject(e1))

p1 = Project ()

print("Project Id: ", p1.allocateproject(c1));

p2 = Project();

print("Project Id: ", p2.allocateproject(e4));

Marks Distribution [40 Marks]:

1. Implementation of Salary class : 2 Marks

2. Implementation of Employee class : 8 Marks


1. Declaration of 6 instance variables : 3 marks
2. Constructor : 1 mark
3. 5 Getter methods :1 mark
4. Validate Telephone No method :3 marks

3. Implementation of Permanent Employee class : 10 Marks


1. Declaration of 3 instance variables : 1.5 marks
2. Constructor : 2 marks
3. Validate Type of Employee method : 2.5 marks
4. Calculate Salary method : 4 marks

4. Implementation of Consultant class : 10 Marks


1. Declaration of 3 instance variables : 1.5 marks
2. Constructor : 2 marks
3. Calculate Salary method : 6.5 marks

5. Implementation of Project class : 10 Marks


1. Declaration of 4 instance variables : 2 marks
2. Constructor : 2 marks
3. Allocate Project method : 6 marks

Anda mungkin juga menyukai