 So one of the things we've been talking about with methods is this idea of being able to reuse the code and this actually you know, we add a new five dollar word to the Kind of vocabulary and it's known as modular rising. I even I take a second to get it properly Said but this idea of modular rising what's actually going on here is what we are looking at is the fact that Now instead of me having to copy and paste something like the distance formula over and over again I have it in once I have it in one spot and Now if I have any problems, I can fix it in my one spot not you know in one spot And then I got a copy and paste it again and again I'm lazy want to do one thing once so let's actually implement this distance method for a second so What we could look at is again, I've already kind of built out the basic portion but Again, I don't even care about my main method. The first thing I care about is making myself a Method for the distance formula so again if we think about how we've kind of discussed it earlier I want to go ahead and design out this method that is gonna return back a double and then I'm gonna just call it Because again, we're designing out the distance formula again Start with the structure worry about the code in just a second now I have some parameters that I have to use I have four parameters a double x1 a double y1 a Double x2 and a double y2 All right, so we've taken care of that. That's pretty nicely done Now what we can do is we can start to do that mathematical equation, you know This guy that's just looming over us Again, just like we saw when we were doing this inside the main method tackle this in smaller chunks I actually like to Write it out like this double x because I'm gonna do first that Formula for x2 minus x1 math dot how x2 minus x1 to that takes care of all of the Problems of just dealing with that all wrapped up into a nice little bow now since I've built that and luckily again Notice how similar that is to the y formula. I can just take this line copy and paste now all I have to do is Replace x with y and I've already tackled, you know this portion in this portion pretty nice Now what I can do is I can finally Calculate out the distance now for my sake. I don't recommend naming it distance Don't you know, don't put distance inside the distance because I'm already using that name here I don't want to name The variable inside the method the same thing as the methods name it in my opinion it gets a little too confusing So I would recommend more maybe a shorthand dist equals math dot sqrt the square root x plus y And guess what that takes that equation now and it just kind of has built it out I now have the distance formula, but again, I have to return I have to Return return something here otherwise All of that goes for not and not to mention you know java is actually going to complain because I don't have a return statement Well, the entire purpose of this was to return the distance between these two points. So why don't we just return? dist now This tiny little program Exists only in a tiny little world. I need to go ahead and design out something inside of my main method I've got a few different things I can think about it if we do collision detection again. We had a few different variables. We had a Double a A x I'll call it ax. We'll say five we had a double a Y which was also five. So it was at the five five point We had a double bx which was also at the five But that double b y was at the zero Now all of a sudden all right just let's see what the distance formula for this is a and b All right. Well What do I do? Well again, I need to probably store this for later use. So dist a b is going to equal the Distance from a x a Y b x b y And what happens is ax is going to get renamed to x1 a y is going to be renamed to y1 b x is going to be renamed to x2 b y is going to be renamed to Y2 again. All right. Well, let's just do a system dot out dot print L in on this I like to you know do print statements all over the place that way I can just test this out and so if we then bring out our console and we Test out our program Compiles fine. All right, excellent. And if we go ahead and say Java test Five we know that that's true because if we think about it, here's the Five five point. Here's the five zero point. Yes, actually it would be here Here's the five five point. Here's the five zero point What I'm doing is I now have Five I know that that's a value. I know that's right well, let's add in my character all of a sudden double CX and I believe we said he was at zero and then double C Y Was that one? Actually, I think there we go Because this if we remember correctly if I had a little bit of a let me draw this out a little bit for us Just for a moment. Here's five five Here's five Zero that's a line. That's a terrible line. That's the worst line ever in line-making class That was a little better But then we also say we got a point right here five one so No, I don't want to save that five one Well again because we're lazy programmers copy Paste instead of this being a B. This is gonna be C a this is gonna be CB C C a a C C B B So now all right. Well, let's keep that distance formula for AB and then let's take another one and do it for C a And if we remember how collision detection kind of worked if I take C a plus C B and if those two added together Equal a B. I'm all set now the beautiful thing again. Look at this. I'm reusing That distance method that we've just created. I only had it set once And I don't have to worry about it anymore So let's actually take a look at this now Java C Compile perfectly fine Java test five five collision detected