4.11 Method challenge
hello in the previous course we how to declare a method and how to use a method in this we will correct the last challenge that we have set up this challenge consisted in creating a method that will allow to ... calculate the final score of the user, we will start declaring our method outside our method. but public static void the name of our method maybe userScoreFinal the heart of our method will contain the condition ... that we performed for the previous challenge, that is. we will copy our if condition and put it in our method, you will have reds for variables ... that are not declared. We'll put these variables as parameters in our method. First parameter gameOver which is a boolean then there is the score which is an integer and the bonus ... which is an integer and finally the final score which is also an integer so we have our method ... userScoreFinale with the condition, we will call our method in our main method so score forgives userScoreFinal and in argument ... we will put the variables that correspond to the parameters we have put we put, that is Game over which is a booleanescore which has a bonus integer which is an integer and the score... final which also has an integer and don't forget to initialize score finalto0as we java a variable ... which is not initialized not to be used. We have to be very careful about the arguments we pass as parameters to our in parameter of our method here if we change the ... first argument which is a boolean to an integer for example gameOver to score which is an integer and . the second parameter we put a boolean the score we gameOver we will have an error because the ... first parameter is a boolean variable the first argument must be a boolean and this applies for all ... the arguments The type of argument must be identical to the type passed in parameter, let's run the program and see the result, we have ... the scoreFinal We could have put only one parameter on our method i.e. Game over to know if the game is over ... or not and declare a variable score where bonus and Final score in the other method we will simply copy ... our declaration here and put them in our method. And in the parameter we will delete the3variables that we have put in our parameter there will remain ... only gameOver and as our method has only one parameter we will also remove the we will also delete the3arguments that we have put ... in the call of our method so it will remain only gameOver and our program will work exactly the same running our program to know the final score which is equal to the previous program so 1200 we can modify the value of ... gameOver to false which means that the game is not finished so our method works correctly since the execution has no ... value so the condition that we put in our method i.e. if gameOver equalsfalse we return ... nothing we have seen that our method works correctly in the next in the next lesson we are going to perform different types of challenges that ... will allow us to take in hand the construction of the methods see you soon