1 00:00:00,270 --> 00:00:05,400 In part two, your challenge was to code the logic to determine the winner so we can jump right into 2 00:00:05,400 --> 00:00:10,320 task four, which tells us to write a function that compares your choice against the computer's choice 3 00:00:10,320 --> 00:00:12,030 to determine the game results. 4 00:00:12,540 --> 00:00:14,790 I already have the function defined for you. 5 00:00:14,910 --> 00:00:16,440 It returns a string. 6 00:00:17,480 --> 00:00:22,340 And it takes two parameters string your choice and string computer choice. 7 00:00:22,820 --> 00:00:26,780 So it's going to use your choice and the computer's choice to determine who won. 8 00:00:27,170 --> 00:00:32,509 Then it's going to return a string that represents the game results for now, the result being returned 9 00:00:32,509 --> 00:00:33,380 as an empty string. 10 00:00:33,380 --> 00:00:38,750 But we're going to update the result according to seven different scenarios that could occur here. 11 00:00:38,750 --> 00:00:42,710 I outlined every scenario where the user wins or loses. 12 00:00:43,610 --> 00:00:47,510 So all you have to do is rewrite each scenario as a condition. 13 00:00:47,600 --> 00:00:51,290 So we're going to start by checking if your choice. 14 00:00:53,350 --> 00:00:54,580 Equals rock. 15 00:01:00,050 --> 00:01:01,820 And the computer's choice. 16 00:01:09,450 --> 00:01:10,740 Equal scissors. 17 00:01:16,200 --> 00:01:17,100 Then you win. 18 00:01:17,100 --> 00:01:19,690 So we're going to set result equal to you win. 19 00:01:19,710 --> 00:01:21,330 That's what's going to get returned. 20 00:01:26,630 --> 00:01:32,720 Then in case that doesn't run, we'll check for the opposite scenario where the computer chooses rock. 21 00:01:36,010 --> 00:01:36,280 In. 22 00:01:36,280 --> 00:01:36,760 You, too. 23 00:01:36,790 --> 00:01:37,660 Scissors. 24 00:01:49,210 --> 00:01:53,200 In which case we're going to set the result equal to you would lose. 25 00:01:58,710 --> 00:02:00,510 So there are five more conditions. 26 00:02:00,510 --> 00:02:01,950 I'm going to leave the rest up to you. 27 00:02:01,950 --> 00:02:03,540 And just fast forward from here. 28 00:02:06,260 --> 00:02:10,430 So at this point, we coded every possible scenario and we're done task for. 29 00:02:14,870 --> 00:02:19,670 So when we call this function, it's going to take your choice and the computer's choice, it's going 30 00:02:19,670 --> 00:02:23,240 to evaluate both values against every single condition. 31 00:02:23,630 --> 00:02:27,830 Then it's going to return a result based on which condition ends up being true. 32 00:02:28,490 --> 00:02:30,530 So we can call this function for main. 33 00:02:35,270 --> 00:02:38,660 And we're going to store the result of the game in a variable results. 34 00:02:51,360 --> 00:02:56,180 All right, before we move to task five, I want to see if the function returns the right results. 35 00:02:56,190 --> 00:02:58,350 So I'm going to print the result in main. 36 00:03:02,990 --> 00:03:04,460 And test my code. 37 00:03:19,930 --> 00:03:20,270 Hmm. 38 00:03:20,290 --> 00:03:21,070 It's a tie. 39 00:03:21,100 --> 00:03:22,180 Let me try again. 40 00:03:22,210 --> 00:03:23,410 I feel like winning. 41 00:03:25,640 --> 00:03:27,440 And I guess I'm just never going to win. 42 00:03:27,440 --> 00:03:30,290 But I like that we now have a fully functional game. 43 00:03:39,280 --> 00:03:41,920 Anyways onwards to Task five. 44 00:03:42,930 --> 00:03:43,170 All right. 45 00:03:43,170 --> 00:03:48,420 So Task five tells us to write a function that prints your choice, the computer's choice and the results. 46 00:03:48,570 --> 00:03:50,980 So we're going to say public static. 47 00:03:51,000 --> 00:03:54,660 The function is void because I don't see anything about a return value. 48 00:03:57,120 --> 00:03:59,250 It's going to be called print result. 49 00:03:59,490 --> 00:04:02,180 And as you can see, it takes three parameters. 50 00:04:02,190 --> 00:04:03,870 String your choice. 51 00:04:10,880 --> 00:04:14,360 Strange computer choice and strange results. 52 00:04:16,100 --> 00:04:19,940 And inside the function, I'm going to print your choice, the computer's choice, and the results. 53 00:04:19,940 --> 00:04:21,560 So I'll just move these. 54 00:04:25,170 --> 00:04:26,040 Over here. 55 00:04:48,400 --> 00:04:49,630 And we're all done. 56 00:04:49,660 --> 00:04:54,700 Congratulations on making it this far and building your second interactive game in Java. 57 00:04:55,150 --> 00:04:59,200 In the next section, we're going to add another skill to our Java toolbox. 58 00:04:59,200 --> 00:05:01,570 The ability to run code in a loop.