Now we can wrap up the Quidditch application by gluing everything together inside Main.
First, when a great string constants to represent the file names.
Static final string teams file.
Is equal to a relative path.
Place file is also equal to a relative path.
Why do I say a relative path when you run your application, your terminal points to the Quidditch game,
but our files are inside the main folder.
So if we just write plays that text.
Or teams that text the compiler is going to look for these files inside a Quidditch game folder and
you're going to get a file not found.
So what you need to do is copy the relative path.
The path relative to the Quidditch game folder.
We're basically going to be telling the terminal, hey, the file we want to open is not inside the
folder Quidditch game, you need to drill further into source main in order to find plays, not text.
And we'll do the same thing here.
Our next task is to create a function that retrieve the data from the teams, file the function, returns
a two day array.
It's called Get Data.
And throws a file not found exception.
Inside the function, create a new object of the file input stream class, and we'll use the file input
stream to connect to the team's file.
And after connecting to the file, you can read the data using scanner scanner scan file is equal to
a new scanner that receives input from the file input stream.
The teams file has two lines, so I'm going to start by creating an array of strings, string lines.
And each element is going to read the next line from the teams file.
And now what I can do is return a Tatiara.
Each row in the teaser rate is going to contain the result from splitting each line into an array of
strings around the comma separator will split the first line into a row of string values.
And split the second line into a row of string values.
OK, so we're returning to rows and each row contains the data for one team, and that's all for that.
Now, inside mean I can create a game object from the data we extracted and you can copy over what I
left you in the article.
I'm going to have to credit to Draycott data to stay consistent.
getData throws a checked exception Soloff to try to run the code.
And catch the exception if it fails.
Let's use break points to make sure everything's good.
And perfect, all the data is there, so I can rest assured the game object gets initialized correctly.
OK, task force to create a function that starts the game of Quidditch.
The function is going to be void.
And inside the function, could a new object of the Phalen bitstream class.
And we'll use the input stream to connect to the plays file.
And after connecting to the file, where can you read the data using scanner scanner, scan file is
equal to a new object of the scanner class that receives input from the input stream.
And now I'm going to run a while loop that keeps running as long as there is a next line.
And whenever there is a next line, that's the play that we need to pass into a game that simulates.
Game out, simulate returns, a simulation of that play, which we're going to print in, already left
you a print here and in the articles of copy it over.
OK, and now we'll do some cleaning up.
And call the function from Main.
Run your code.
And this is really cool, it actually simulates a game of Quidditch players are randomly selected from
each team to simulate plays.
All right, but what's the final results?
So at another function called the print results.
First, I'll get the Gryffindor team.
I'll also get the leather and team.
And this function needs to determine the winner.
So I'll say Timoner.
And if Gryffindor, a score is higher than slither in.
Return Gryffindor is the winner, otherwise return slither in.
And now just copy over the print line format from the article or even from here.
And update the placeholders where necessary.
Kate, now you can call the function from Main.
And this is looking really, really good, but, you know, it would be really nice if there was a three
second delay between play so that it looks like there's a game happening in real time.
In the article, I told you to create a function that sleeps for X amount of seconds.
Public void Wait.
It takes a parameter that tells it how long to wait for, and your task was to look into the time unit
class.
And I hope you came up with this.
Time unit, the second sleep, and we wanted to sleep for however many seconds the color specifies,
this function throws a checked exception.
So we'll try to run the code.
And catch the exception if the code fails.
And inside will print the message that the exception comes with.
And all right, we're almost done.
Last thing we got to do is wait three seconds before simulating each play.
And with the last line of code, I'm proud to say that we're all done.
That was a really long project.
Let's just run the code one last time.
It's looking good and wow, this is fantastic.
It feels like it's happening in real time.
This is definitely my favorite project in this module.
I really hope you enjoyed it.