In part two, your challenge was to code the logic to determine the winner so we can jump right into
task four, which tells us to write a function that compares your choice against the computer's choice
to determine the game results.
I already have the function defined for you.
It returns a string.
And it takes two parameters string your choice and string computer choice.
So it's going to use your choice and the computer's choice to determine who won.
Then it's going to return a string that represents the game results for now, the result being returned
as an empty string.
But we're going to update the result according to seven different scenarios that could occur here.
I outlined every scenario where the user wins or loses.
So all you have to do is rewrite each scenario as a condition.
So we're going to start by checking if your choice.
Equals rock.
And the computer's choice.
Equal scissors.
Then you win.
So we're going to set result equal to you win.
That's what's going to get returned.
Then in case that doesn't run, we'll check for the opposite scenario where the computer chooses rock.
In.
You, too.
Scissors.
In which case we're going to set the result equal to you would lose.
So there are five more conditions.
I'm going to leave the rest up to you.
And just fast forward from here.
So at this point, we coded every possible scenario and we're done task for.
So when we call this function, it's going to take your choice and the computer's choice, it's going
to evaluate both values against every single condition.
Then it's going to return a result based on which condition ends up being true.
So we can call this function for main.
And we're going to store the result of the game in a variable results.
All right, before we move to task five, I want to see if the function returns the right results.
So I'm going to print the result in main.
And test my code.
Hmm.
It's a tie.
Let me try again.
I feel like winning.
And I guess I'm just never going to win.
But I like that we now have a fully functional game.
Anyways onwards to Task five.
All right.
So Task five tells us to write a function that prints your choice, the computer's choice and the results.
So we're going to say public static.
The function is void because I don't see anything about a return value.
It's going to be called print result.
And as you can see, it takes three parameters.
String your choice.
Strange computer choice and strange results.
And inside the function, I'm going to print your choice, the computer's choice, and the results.
So I'll just move these.
Over here.
And we're all done.
Congratulations on making it this far and building your second interactive game in Java.
In the next section, we're going to add another skill to our Java toolbox.
The ability to run code in a loop.