1 00:00:00,210 --> 00:00:03,810 Before we start, did you try solving the workbook yourself? 2 00:00:03,840 --> 00:00:09,600 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,900 --> 00:00:12,820 Welcome to Workbook 5.9. 4 00:00:12,820 --> 00:00:17,110 Task one is to prompt the user to enter their username and password. 5 00:00:17,110 --> 00:00:28,300 So here we're going to say string, user name entry, whatever they enter is equal to skin next line. 6 00:00:29,990 --> 00:00:32,630 And then string password entry. 7 00:00:34,220 --> 00:00:36,590 Is equal to the password they enter. 8 00:00:36,890 --> 00:00:43,550 And then task two is to set up a loop that keeps running while the username or password they input is 9 00:00:43,550 --> 00:00:44,540 incorrect. 10 00:00:44,660 --> 00:00:52,340 So while the username that they enter does not equal the actual username. 11 00:00:54,350 --> 00:01:01,730 Or if the password is incorrect, if password entry does not equal the actual password. 12 00:01:03,780 --> 00:01:09,930 Then we need to keep running this while loop and keep re prompting them to enter correct credentials. 13 00:01:09,930 --> 00:01:11,160 So here we have to say. 14 00:01:11,160 --> 00:01:13,110 System.out.println. 15 00:01:14,560 --> 00:01:15,010 I don't know. 16 00:01:15,010 --> 00:01:16,690 What was the actual message here? 17 00:01:17,200 --> 00:01:17,800 Incorrect. 18 00:01:17,800 --> 00:01:18,640 Please try again. 19 00:01:18,670 --> 00:01:22,120 Seems there's a line of space before and a line of space after. 20 00:01:22,120 --> 00:01:23,890 So incorrect. 21 00:01:25,500 --> 00:01:27,690 Please try again. 22 00:01:30,500 --> 00:01:33,200 Giving them the chance to update their username. 23 00:01:36,500 --> 00:01:37,880 And their password. 24 00:01:46,300 --> 00:01:49,540 And actually, I think the input looks a bit different. 25 00:01:50,410 --> 00:01:56,890 Don't forget your print statements because they need to enter their username beside a prompt of username, 26 00:01:56,890 --> 00:02:00,430 their password beside a prompt of password. 27 00:02:00,460 --> 00:02:03,490 And I think now we should be good. 28 00:02:04,210 --> 00:02:06,880 Do we print anything after it's successful? 29 00:02:07,300 --> 00:02:13,150 So if they guess it right, that means the loop broke, in which case we print. 30 00:02:13,960 --> 00:02:14,320 I don't know. 31 00:02:14,320 --> 00:02:15,400 You can print anything you want. 32 00:02:15,400 --> 00:02:16,720 We'll say success. 33 00:02:20,990 --> 00:02:24,350 All right, Time to visualize the runtime. 34 00:02:29,690 --> 00:02:32,870 So if I guess wrong, I'll say Ryan. 35 00:02:34,980 --> 00:02:35,780 Password? 36 00:02:35,790 --> 00:02:36,420 I don't know. 37 00:02:36,690 --> 00:02:37,260 Items. 38 00:02:37,260 --> 00:02:38,370 One, two, three. 39 00:02:40,160 --> 00:02:43,460 So if we look here, the username entry is Ryan. 40 00:02:43,490 --> 00:02:45,440 The actual username is Samantha. 41 00:02:45,680 --> 00:02:47,450 The password entry is Adam's. 42 00:02:47,450 --> 00:02:48,260 One, two, three. 43 00:02:48,290 --> 00:02:51,190 The actual password is I love Java. 44 00:02:51,200 --> 00:02:54,830 This evaluates to true because the user names don't equal each other. 45 00:02:54,830 --> 00:02:58,130 This evaluates a true because the passwords don't equal each other. 46 00:02:58,130 --> 00:03:03,920 So this entire thing will be true, prompting us to enter our username again. 47 00:03:04,100 --> 00:03:06,830 So here I'll actually input the correct username. 48 00:03:06,830 --> 00:03:07,700 Samantha. 49 00:03:14,680 --> 00:03:17,520 But I will put in the incorrect password. 50 00:03:17,530 --> 00:03:20,680 I will put in a password of I don't know. 51 00:03:20,680 --> 00:03:23,710 I will put in the same incorrect password of one, two, three. 52 00:03:25,300 --> 00:03:30,900 So while the username entry does equal the username, this is going to evaluate to false. 53 00:03:30,910 --> 00:03:35,390 However, the password entry does not match the actual password. 54 00:03:35,410 --> 00:03:39,130 This evaluates to true because we're using the or operator. 55 00:03:39,160 --> 00:03:41,680 This whole thing is going to become true. 56 00:03:41,710 --> 00:03:45,550 We entered incorrect credentials prompting us to try again. 57 00:03:46,510 --> 00:03:50,050 This time I will put in a correct username of Samantha. 58 00:03:55,370 --> 00:03:59,300 I will put in the correct password of I love Java. 59 00:04:01,770 --> 00:04:03,030 All right, moving on. 60 00:04:03,700 --> 00:04:10,090 This time this evaluates the faults because they do equal this evaluates the false as well, because 61 00:04:10,090 --> 00:04:16,600 the passwords do equal, because this whole thing evaluated the false, the while loop breaks. 62 00:04:17,570 --> 00:04:19,310 And it prints success.