You are on page 1of 5

Practical

Programming in C# Page 1 of 5
Question 1
I. Create an interface IEmployee that has the following methods:
- double CalculateBonus(string designation, int tenure, double salary):
calculate bonus of employee.
- void DisplayDetails();

II. Create a class Employee inherits from interface IEmployee.

1. Fields – private:

• string _EmpName: Name of Employee


• int _yearsOfService: time work of Employee.

2. Fields – protected

• double _bonus: Bonus of employee.

3. Fields – public

• string Designation: position of Employee.


• double Salary: Salary of Employee.

4. Properties:
• string EmpName – Name of employee: R/W. Length of Name from
6 to 40 characters.
• int YearsOfService – Years of Service of employee: R/W. Value of
YearsOfService from 0 to 60.

Note:
i. R/W: Read-write property.
ii. R: Read property.
iii. W: Write property.

5. Methods: Implement 2 method of interface IEmployee.

- Method CalculateBonus(string designation, int tenure, double salary):


Calculate bonus of employee follow formula:

if designation is Manager then


if tenure <= 5 then
Bonus = salary * 1.5
else
Bonus = salary * 2

if designation is Engineer then


if tenure <= 5 then
Bonus = salary
else

Programming in C# Page 2 of 5
Bonus = salary * 2
if designation is Technician then
if (tenure <= 3) then
Bonus = salary * 0.25
else if (tenure > 3 and tenure <= 5)
Bonus = salary * 0.5
else
Bonus = salary * 2
- Method DisplayDetails(): Display all information of employee and total
income earned is salary + bonus.

III. Declaring class NewEmployee inherits from class Employee.

1. Methods:

- Override method CalculateBonus(string designation, int tenure, double


salary) and add calculate bonus for designation is Teacher follow
formula:

if tenure <= 3 then


Bonus = salary * 3
else
Bonus = salary * 4

- Override method DisplayDetails()

IV. Create a class EmployeeTest to test classes: Define an instance of


NewEmployee class. Please demo by get EmpName, YearsOfService from
the keyboard and Designation, Salary get by menu follows:
Create menu to select the designation and Salary:
If select 1 then
Designation is Manager and Salary is 5000.
If select 2 then
Designation is Engineer and Salary is 4000.
If select 3 then
Designation is Technician and Salary is 3000.
If select 4 then
Designation is Teacher and Salary is 2000.
Else
Print “Invalid option selected”

Show all information just entered to the screen:

Programming in C# Page 3 of 5
Question 2 : The program demonstrates the use of Constructor and Indexers.
I. Create class Person:

1. Fields – Private:

o string _IDCard: ID Card of Person.


o string _name: Name of Person.
o int _age: Age of Person.

2. Properties:

o string IDCard – ID Card of Person: ReadOnly.


o string Name – Name of Person: ReadOnly.
o int Age – Age of Person: ReadOnly

3. Create constructor with three parameters to initialize the ID Card, Name


and Age.

II. Create class PersonVietNam

1. Creating a private array of class Person.


2. Constructor with one parameter to initialise the length of the array.
3. Indexer to set and get the values of Persons in the array.
4. the values stored in the array
Create method call DisplayDetails() to display
III. Create class PersonTest is user to test the PersonVietNam class.

1. Create 2 Person. [0.5]


2. Create 1 PersonVietNam, then assign these Person into the array via
Indexer
3. Invoking the DisplayDetails method to display the PersonVietNam
details.

Programming in C# Page 4 of 5
-----THE END-----

Programming in C# Page 5 of 5

You might also like