6.5 OOP Setters

Hello, in the previous course, we have seen getteur how to create and how to call them in our hand method, in ... our course, we will look at setteur recallyou that a setteur allows you to request a change of state so to create a setteur you put public void setNam and there will be a parameter the parameter will match the name we will give to our city so it will be a string of characters String name Since the setteur allows you to modify our variable name It will be necessary that the parameters be equal to the name so we can think and put name equal to name but except that there, There’s an inconsistency in the fact that the name we put here is exactly the same as the name we put in parameters, so we made name equals name. What is inconsistent So how we tell Java that we want the name of our class to be equal to the parameters we put in our setteur. so how do we say to java that we want to challenge this field, that is to say the name field so that the ... value of this parameter is equal to the name of in our class To do this, we need the keywords this. which will allow to specify to Java that we are referring to the field of our object on which this method ... was called so we will put the keyword this here this point name that isIn other words, the name here corresponds to the variable String name and you had to put it especially for spotters, that is to say that here, we put this name Now we will go back to our method. and in the main method we will put in comment this two line and we will call our Setteur we will put Paris point setteur name and there we can indicate the name we want to put for our city we will put Paris and by doing this our city, The name of our city is Paris so we will call the getter so that he can return the name we put for our city in the print Paris point getNom and by compiling our program In the console, we will have Paris displayed. Paris we have two Paris since in the manufacturer. in our builder we put this just put in comment and we will recompile our program in the console, we had only one Paris that corresponds to the name we put in the setteur So here the argument of our setteur is Paris but we can make checks in the setteur to check if it corresponds well if it is Paris the argument. Back in our city class we’ll put a condition in our setteur if name equal Paris we can say, we can copy line 26 and put it in our condtion if our argument that we are going to put corresponds to Paris The name of our class will be lost to the name that we put in parameter but otherwise this name will be equal to the error There, We’ll go back in our hand to check this condition. First, we will compile if it works correctly So, in the console, we have Paris. But let’s change Paris and put Nice for example in the console, we’ll have a mistake. Since we’re doing a check on the name Now, you’ve become aware of the getter setter and the keyword this we’re going to do our challenge. I’ll create a record. challenge The challenge is to create and a calculator that isto say it will have the subtracted additions of the multiplications so I will let you take the time to take a good look I will zoom in on the challenge to look good and read well to understand what you need to do in the next course we will Fix this challenge take the time to do it right soon.