1 00:00:00,600 --> 00:00:04,680 Now we can wrap up the Quidditch application by gluing everything together inside Main. 2 00:00:08,410 --> 00:00:11,440 First, when a great string constants to represent the file names. 3 00:00:13,920 --> 00:00:16,140 Static final string teams file. 4 00:00:19,820 --> 00:00:21,770 Is equal to a relative path. 5 00:00:26,330 --> 00:00:29,240 Place file is also equal to a relative path. 6 00:00:29,780 --> 00:00:35,380 Why do I say a relative path when you run your application, your terminal points to the Quidditch game, 7 00:00:35,780 --> 00:00:38,330 but our files are inside the main folder. 8 00:00:41,110 --> 00:00:43,570 So if we just write plays that text. 9 00:00:49,270 --> 00:00:55,570 Or teams that text the compiler is going to look for these files inside a Quidditch game folder and 10 00:00:55,570 --> 00:00:57,090 you're going to get a file not found. 11 00:00:57,580 --> 00:01:00,790 So what you need to do is copy the relative path. 12 00:01:03,900 --> 00:01:06,600 The path relative to the Quidditch game folder. 13 00:01:08,140 --> 00:01:13,120 We're basically going to be telling the terminal, hey, the file we want to open is not inside the 14 00:01:13,120 --> 00:01:19,510 folder Quidditch game, you need to drill further into source main in order to find plays, not text. 15 00:01:20,640 --> 00:01:21,960 And we'll do the same thing here. 16 00:01:35,290 --> 00:01:40,180 Our next task is to create a function that retrieve the data from the teams, file the function, returns 17 00:01:40,180 --> 00:01:40,990 a two day array. 18 00:01:42,790 --> 00:01:43,840 It's called Get Data. 19 00:01:52,750 --> 00:01:54,760 And throws a file not found exception. 20 00:02:00,280 --> 00:02:05,860 Inside the function, create a new object of the file input stream class, and we'll use the file input 21 00:02:05,860 --> 00:02:07,720 stream to connect to the team's file. 22 00:02:14,450 --> 00:02:20,870 And after connecting to the file, you can read the data using scanner scanner scan file is equal to 23 00:02:20,870 --> 00:02:24,230 a new scanner that receives input from the file input stream. 24 00:02:31,500 --> 00:02:36,870 The teams file has two lines, so I'm going to start by creating an array of strings, string lines. 25 00:02:44,350 --> 00:02:48,250 And each element is going to read the next line from the teams file. 26 00:02:59,170 --> 00:03:01,420 And now what I can do is return a Tatiara. 27 00:03:09,810 --> 00:03:15,030 Each row in the teaser rate is going to contain the result from splitting each line into an array of 28 00:03:15,030 --> 00:03:20,490 strings around the comma separator will split the first line into a row of string values. 29 00:03:29,450 --> 00:03:32,540 And split the second line into a row of string values. 30 00:03:45,240 --> 00:03:51,120 OK, so we're returning to rows and each row contains the data for one team, and that's all for that. 31 00:03:52,480 --> 00:03:57,610 Now, inside mean I can create a game object from the data we extracted and you can copy over what I 32 00:03:57,610 --> 00:03:58,600 left you in the article. 33 00:04:13,310 --> 00:04:16,790 I'm going to have to credit to Draycott data to stay consistent. 34 00:04:21,019 --> 00:04:24,650 getData throws a checked exception Soloff to try to run the code. 35 00:04:34,140 --> 00:04:36,180 And catch the exception if it fails. 36 00:04:47,080 --> 00:04:49,170 Let's use break points to make sure everything's good. 37 00:05:01,800 --> 00:05:07,470 And perfect, all the data is there, so I can rest assured the game object gets initialized correctly. 38 00:05:18,010 --> 00:05:21,580 OK, task force to create a function that starts the game of Quidditch. 39 00:05:25,320 --> 00:05:26,700 The function is going to be void. 40 00:05:34,200 --> 00:05:37,770 And inside the function, could a new object of the Phalen bitstream class. 41 00:05:40,470 --> 00:05:43,530 And we'll use the input stream to connect to the plays file. 42 00:05:47,330 --> 00:05:52,340 And after connecting to the file, where can you read the data using scanner scanner, scan file is 43 00:05:52,340 --> 00:05:56,960 equal to a new object of the scanner class that receives input from the input stream. 44 00:05:59,170 --> 00:06:03,550 And now I'm going to run a while loop that keeps running as long as there is a next line. 45 00:06:08,920 --> 00:06:14,410 And whenever there is a next line, that's the play that we need to pass into a game that simulates. 46 00:06:20,760 --> 00:06:26,550 Game out, simulate returns, a simulation of that play, which we're going to print in, already left 47 00:06:26,550 --> 00:06:29,580 you a print here and in the articles of copy it over. 48 00:06:44,420 --> 00:06:46,160 OK, and now we'll do some cleaning up. 49 00:07:03,130 --> 00:07:04,660 And call the function from Main. 50 00:07:12,280 --> 00:07:13,120 Run your code. 51 00:07:24,310 --> 00:07:29,860 And this is really cool, it actually simulates a game of Quidditch players are randomly selected from 52 00:07:29,860 --> 00:07:31,570 each team to simulate plays. 53 00:07:31,960 --> 00:07:34,000 All right, but what's the final results? 54 00:07:41,210 --> 00:07:43,520 So at another function called the print results. 55 00:07:59,390 --> 00:08:01,160 First, I'll get the Gryffindor team. 56 00:08:14,210 --> 00:08:15,830 I'll also get the leather and team. 57 00:08:20,580 --> 00:08:22,710 And this function needs to determine the winner. 58 00:08:25,410 --> 00:08:26,820 So I'll say Timoner. 59 00:08:34,030 --> 00:08:36,970 And if Gryffindor, a score is higher than slither in. 60 00:08:59,340 --> 00:09:02,940 Return Gryffindor is the winner, otherwise return slither in. 61 00:09:05,200 --> 00:09:09,160 And now just copy over the print line format from the article or even from here. 62 00:09:18,820 --> 00:09:21,580 And update the placeholders where necessary. 63 00:10:11,260 --> 00:10:13,120 Kate, now you can call the function from Main. 64 00:10:33,290 --> 00:10:38,570 And this is looking really, really good, but, you know, it would be really nice if there was a three 65 00:10:38,570 --> 00:10:43,070 second delay between play so that it looks like there's a game happening in real time. 66 00:10:43,820 --> 00:10:47,870 In the article, I told you to create a function that sleeps for X amount of seconds. 67 00:10:56,580 --> 00:10:57,900 Public void Wait. 68 00:10:59,960 --> 00:11:06,050 It takes a parameter that tells it how long to wait for, and your task was to look into the time unit 69 00:11:06,050 --> 00:11:06,650 class. 70 00:11:12,010 --> 00:11:13,330 And I hope you came up with this. 71 00:11:14,880 --> 00:11:22,380 Time unit, the second sleep, and we wanted to sleep for however many seconds the color specifies, 72 00:11:23,100 --> 00:11:25,250 this function throws a checked exception. 73 00:11:25,530 --> 00:11:27,090 So we'll try to run the code. 74 00:11:32,790 --> 00:11:35,070 And catch the exception if the code fails. 75 00:11:46,250 --> 00:11:49,460 And inside will print the message that the exception comes with. 76 00:11:53,310 --> 00:11:54,720 And all right, we're almost done. 77 00:11:57,680 --> 00:12:01,750 Last thing we got to do is wait three seconds before simulating each play. 78 00:12:03,660 --> 00:12:07,020 And with the last line of code, I'm proud to say that we're all done. 79 00:12:07,470 --> 00:12:08,940 That was a really long project. 80 00:12:09,600 --> 00:12:11,480 Let's just run the code one last time. 81 00:12:23,370 --> 00:12:27,100 It's looking good and wow, this is fantastic. 82 00:12:27,120 --> 00:12:29,070 It feels like it's happening in real time. 83 00:12:29,880 --> 00:12:32,820 This is definitely my favorite project in this module. 84 00:12:32,850 --> 00:12:34,250 I really hope you enjoyed it.