Welcome to my lovely students, very happy that you're here with me.
Let's go over the inheritance practice assignments.
OK, so we have covered all the theory topics and it's now time to practice, OK, practice time of
war.
We need to defeat the assignment.
We need to break it down into pieces and we need to get the resolution.
This is not an easy task.
So it would be a bit more challenging than previous ones.
And it's OK.
Even if you get partial resolution, you need to try.
You need to fight with it.
You need to get the resolution by yourself and not just to see the answers.
OK, so I highly recommend you to try to resolve it by yourself and in the next video to compare your
answers to mine.
OK, so let's begin.
First of all, obviously, I would ask you to create two classes, one parent class employee, and the
second one would be child class programer.
And you would obviously have a relationship of parent child between these two classes as employee.
Could be either a child, which is a programmer, it could be a product manager, a Q a teacher or other
positions in the IT industry.
OK, but we are going to focus only on one child, which we which will be a programmer.
So we need to create these two classes, parent and child.
OK, so first of all, let's talk about the parent, the employee class and what it will contain.
You would need to create an input method and constructor or init method.
It's the same name for the employee class and it would contain three properties, OK, it would contain
years of experience, position, name and employee name, OK, and then afterwards create a method.
First one we would talk about the second one as well.
The first method inside employee, which with name would be calculate salary.
In here we would need to create a variable, a local variable with an aim calculated salary based on
these parameters.
First of all, create an additional variable and call it base salary in it will be equals to two thousand
five hundred.
Then we're going to add to that base salary, additional money according to the following parameters.
So each employee, each programmer in our case, each employee.
Yeah, each employee would get increase if he has between zero and two years of experience.
Including two years.
OK, so you remember that once we do in comparison, you can do X bigger and you can do also.
The use also equals bigger and not just bigger, right.
So including two.
So between zero and two years of experience, the salary would increase by 1500, meaning this base
salary.
OK, then you have another if if it's if years of experience is between two and five years, including
five salary, it would be increased by two thousand five hundred.
And if that are years of experience is above five years, the base salary would increase by three thousand
five hundred, obviously.
Here I am talking about years of experience.
I mean, you need to use this property right here, OK?
You need to use it inside this method.
Then print the calculated salary and also return the calculated return, the calculated salary.
OK, and you will see why, OK, you already familiar with the return keyword from previous topic topics?
Obviously.
OK, then we have a second method inside the parent.
Inside the employee.
OK, it would calculate the salary based on two properties position, name and years of experience.
OK, again, meaning using these properties right here.
OK, so it would take into consideration these two.
And it would calculate whether the employee needs to get a bonus or not, so creative calculation,
both based on these following parameters, first of all.
I also want to mention here to accept pass the calculated salary variable.
And add bonus on top of it.
OK, so what I mean is, is this method right here or should accept calculated salary?
And on top of that, you should add, OK, you should add, if an employee deserves a bonus, you should
add it on top of this variable.
And how would you do it?
I'm just also I'm like thinking of giving you an additional hint, OK, so I will do it.
So, for example, if I have a variable, for example, if I have instant's, which will be instant's,
maybe programer, maybe like a person, a person, one.
OK, and then we have method one.
So if I have a return action here and sign it said this method.
Yeah.
Inside its method, let's say I have a return action.
Same as I have here.
Yeah.
So if I have a return here I can do the following thing.
I can do this thing.
Yeah.
And that way if I have a return here it will be accepted and sent to here and then this variable I can
use it.
OK, I can do now person one, method two and now I can take this variable and pass it to here.
Right.
So this is exactly what you were asked to do.
You should get this calculated salary, OK, and put it with by using the return action in that method
and then send it to an outer variable like this.
And then this variable should go into the candidates for bonus method.
All right.
So this is like a huge hand, but I think it will be very helpful.
So use this calculated salary and then choose and check whether an employee deserves deserves a bonus.
OK, so here are the following parameters.
A bonus of zero point one out of the monthly calculated salary will be handed to if all front end developers.
How could you check whether an employee is a front end developer?
Check the hint at the end of the page.
So.
Before going to the end of the page, just remember that you have position name, which is a string,
very important.
You have this inside your instance that you need to create.
And you can check whether the property that we just looked, if it contains a Front-End text, you can
do it by the following way.
OK.
This is the hint.
To check whether a certain phrase appears in another phrase by using and if you use the template, this
one if.
String ABC.
Appears in.
This ring ABCDE, then go inside if OK, so Python knows how to check if a certain string appears in
a different string and this is the template, if there's a certain string, you see the quotation marks
here, if a certain string.
Appears in can see here the end in keyword appears in a different string than the if statement would
go inside.
So this is the hint.
So a bonus of zero point one of a monthly calculated salary will be handed to all Fronton developers.
OK, so check the hint that I just gave you how to check whether the position, the position contains
this front end.
OK.
An additional bonus of zero point two will be given to all employees who has above two years of experience.
OK, so all employees that have above two years of experience will get that bonus as well.
Employees cannot get to bonuses.
OK, take it into consideration.
So this covers the second method.
This covers the first method of the employee, which is the parent class.
Now, let's talk about the child's class problem, how this class is a bit more.
Yeah.
So it should inherit all methods and properties, OK?
Should there should be inheritance between programmer and employee and inside this class, you should
get the properties, obviously the init method and also one method.
OK, you should print salary and position in your own sentence.
You can use it in whatever sentence you want.
Just use these to two values, salary and position.
All right.
Use please use string formatting.
As you can see, the programmer is very, very lean.
OK, so I just want you to know what the name of the employee, OK?
And I want it to be less challenging name.
Of employee and position.
OK, so print out these two values.
OK, now once we have covered this class and we have covered this class, I want you to create these
two instances.
OK, so you have the first instance, junior python programmer, and it will get these three values,
one front end.
And Joseph, what all these three mean, very easy.
One front.
And Joseph, let's go to the parent one.
Self years of experience, second front end is the positioning, then Joseph employee name.
OK, so this is the first instance, which is junior python programmer.
This is the name of the instance, the name of the instance.
And these are the values that you should pass to the instance.
You obviously need to create an instance of the child.
Yeah.
This is the second instance, this is its name, senior developes, and to get these three values,
six years of experience, name of the position and the name of the person is Dan.
That's it.
So just going to this part here, you can see that this instance gets front end.
This is the name of the position.
And then going here, OK, you need to check whether it's front end is received by using.
Positioning and the positioning, obviously, for that specific instance, is front end, so the employee
should get this bonus.
Yeah, I think this covers the readout and the walk through of the inheritance assignment, homework
assignment.
It will be challenging.
It's OK.
Just try and try to rely on previous topics and previous lectures regarding inheritance and OLP that
we studied.
I wish you good luck and I will see you in the next lecture.
Thank you.