 Okay, we're back to the inheritance and polymorphism business and I have another example. It's sort of artificial, but it'll have to do. First of all, let's look at the UML diagram. Excuse me, because that's should make things a bit easier. We have a first class which is a blanket which is described by a size, the color and the material it's made of. And we're going to have a static constant called sizes. And I guess I should have put in what kind that is. So let me fix that real quick here. And that is in my description here and sizes which is an array of string or close enough to that is doesn't make any difference. And let's, excuse me here. Wow, I've got a whole bunch of stuff going on here, don't I. Let's go back here to what the heck is the name of this. Okay, and what the heck is this going to be called I called it blankets.punl. And now let's try displaying blankets.png and see if that looks a little better. Okay, yes, there we go. It's static. Sorry about that. Okay, back to business. So let's start, let's start over again. We have our main class, which is the blanket that has a size, color and material, and we're going to have an array of possible sizes. We'll have a constructor. And we can get the size, the color and the material. And we also have a static method for uppercasing the first letter of a string. Why do we need that you'll see in a few minutes. Now blanket has two subclasses electric blanket has everything that a blanket has plus a voltage, the distance between the wires in the blanket, and whether it's turned on or not. And again, has all the appropriate getters and setters. And we have a method that says if you tell me what the wattage is I can tell you how efficient it is. And that's a function of the distance in the wires. This is a totally bogus measurement, but I just needed something that electric blankets have the other subclass of the blanket is a weighted blanket which tells how much weight is inside the blanket. And again, I have a constructor I have the getter for that. No center because once the weight is sewed into the blanket you can't change it. Another two string method and a method for getting the comfort level. And that depends on the weight of the blanket and the weight of the user. So there's my inheritance hierarchy. And let's go and take a look at those classes. So here's the blanket class which has a size color material. I made an array list of strings called sizes. And that's going to be an array list that's based on this array. The reason I need an array list is going to I'll show you in a moment, but here are the possible sizes twin full queen and king. So you're going to give me a size. Now it could be upper and lower case. So I'm going to translate it to lower case. And then I wanted to use the contains method inside of array list. I want to see if the size you gave me in lower case is one of these. And that's why I had to go through this whole long business with an array list. It's a bit more complicated than it should be. Let's go with it. So if our size contains the size you gave me, that's the one I'm going to set. Otherwise, I'll presume it's a twin size blanket, the smallest one. And then I set the color and the material to whatever you gave me the rest of the getters and setters are no big deal. And when I'm doing this to string, if it's a twin or a full, I want to say capital T twin or capital F full. So if you give me something that is not the empty string, I'll uppercase the first letter and then add on the rest of the word all converted to lower case. If you give me the empty string, I'll give you back the empty string. I'm adding these little methods because it made, first of all, it made it more interesting for me to write, and it's also a little bit indicative of what you might run into in the real world. Namely, you can't expect people to give you something that's exactly what you want. They might have it all in capital letters, or they might have it capitalized, they might not. And that's why we have to make sure that we translate it to lower case. And when we display it for the user inside of two string. We want to look nice and that's where we're going to uppercase the first letter. In fact, let's go here and let's just do something real quick. We have a blanket B is going to be a new blanket. And it's going to be, let's say a twin size, let's say full. And it's going to be blue and it's going to be a flannel. Oh, that's exciting. Yes, these are strings. Hello, earth Eisenberg. Since they're all strings, I have to make them strings. There we go. And that's a blue flannel full blanket. Okay, cool. That works like a champ. And then we have an electric blanket, which extends the blanket notes, by the way, I can put as many classes as I want into a file. Only one of them can be public in this case, none of them are. Now, if it's not public, is it private? No, it turns out if I don't put the word public or private. Then that's what's called default access. It's accessible to any other file that's in the same directory. And there's a lot of ins and outs and nuances that I don't want to get into here. But if I leave off the word public or private, it's the default accessibility which is exactly what I want to do in this case. So here are my private properties. And then here's the constructor and you'll notice that I call super to call the super class constructor with the size, the color and the material. I'll set the voltage I'll say it's turned off. So when you construct a new electric blankets turned off, which is probably a good thing. Remember, a getter for a Boolean begins with the word is not the word get. And I can set whether it's turned on or not. Here's the voltage. And then when I want to set the voltage. If you give me 110 or 220, those are valid. Otherwise, I'm going to just presume it's 110 for the United States. And notice by the way, I'm calling that here inside of my constructor so I don't have to duplicate the code. A constructor can call another method inside of the class. And then I print out all of this stuff. And I don't print the wire distance in there. I'm not sure why I didn't do that, but it's not part of that. Let's do that and let's just do quickly see if that works. So if I have an electric blanket. That's a new electric blanket. And it's going to be let's say queen size. Blue cotton. And it's going to be a 220 volt and the wire distance is going to be three centimeters. Is that a double by the way, or not. It's an integer. Okay, so that's pretty widely spaced wires, but we'll worry about that later. Let's check to see if that prints out properly. The cotton queen 220 volt and it's off. Perfect. And then here's the efficiency by the way. Totally bogus measure but I just need an example so electric blankets can have an efficiency depending on the wattage. Now what about our weighted blanket again nothing new here again I'm going to call the superclass constructor. The weight will be the absolute values in case you give me some negative number. I'm not going to let you get away with that. Here's the getter and here's two string. And again another totally bogus calculation based on the user's weight. Now, let's go back to our test method, a test program, excuse me. And this one I do want to be public as a class and it's going to contain our main method, and therefore the class name and the file name have to match. I'm going to create an array of blankets that is populated with regular blankets electric and weighted blankets it's going to have all three types in them polymorphism let's me do that. So I'm going to have blanket. Let's call it blanket list. And that's going to be going to use my curly braces to initialize it the first one is going to be a new blanket. And let's say a full maroon flannel. Then I'm going to have another new blanket. That's going to be a queen size. Oh, let's say it's yellow and cotton. Now I'm going to have an electric blanket. This twin size. It's going to be gray. And it's going to be in fleece. It's also going to have a 220 volts for Europe and the wire distance is going to be 0.5 centimeters. Finally, we'll have a new weighted blanket. That's going to be king size. And let's see what color should we make it. Oh, let's make it tan. And what material should it be let's make it wool. And the weight in kilograms we're going to give it a 15 kilogram weight. Rather than ask the user for input I'm going to just say, let's say that we're going to have our wattage and what's the wattage is that a double or is that it's an integer. Okay. So let's say we have a 20 watts. Okay. Our supply provides this. And we're going to have for the user's weight. We're going to have a double customer weight is going to be let's say, oh, 72.3 kilograms. Now here's what I want to do. I want to say for each blanket be inside of my blanket list. Let's print them all out. Dynamic binding is going to take effect here. The first one is going to call the two string method of blanket. And for the second one for the third one because at runtime we know that it's an electric blanket is going to call two string for the electric blanket. And for the weighted blanket, it's going to call that classes to string method. And let me just make that explicit here so we can see it in action. And oh my goodness. Let's see what am I doing here. Okay, well that's the first thing I've got to do is get rid of that. Let's see if that helps any. And what did I do here. My electric blanket. Oh yes. Okay. I forgot my distance has to be an integer. There we go much better. And let's run that. And you'll notice I have a maroon flannel full a yellow cotton queen. I don't know why it's doing that but this is just amazing that my terminal program seems to figure out these colors. How cool is that I did not plan that that just I just found this out I don't know how it happened but wow. So again dynamic binding is taking care of this. Now here's what we'd like to do. What we'd like to say is for the electric blanket we'd like to tell you what the efficiency is. And for the weighted blanket we'd like to tell you what its comfort level is. So here's what we're going to have to do. We're going to say if B is an instance of, I'm sorry, there's no dot in there. If it's an instance of electric blanket, then what we're going to do is we're going to say, and let's go back here and look at the get efficiency. We're going to say, is it going to become. Now if we try and do this it's not going to compile properly. And the reason it's not going to compile properly is because as far again as far as the compiler is concerned. B is a blanket, because it came from a list of blankets. And a regular blanket doesn't have a get efficiency method in it. What we're going to have to do is we're going to have to do a cast. We know it's safe to do this. Because we know that B is an electric blanket at runtime. We can cast B to an electric blanket telling the compiler no treat this blanket as though it were an electric blanket, and then we will be able to get its efficiency. Similar we can say similarly we can say if B is an instance of weighted blanket, then we can say double comfort. We're going to have to cast it to the correct format. And what did I call that I'm sorry I'm having problems remembering what I called my bogus methods here. Comfort level of customer weight. Let's run that. And so for the electric blanket, we have its efficiency for the weighted blanket. Why does it say zero kilograms? That's not good. We have something crazy going on here. Let's take a quick look and see what's going on with that. I gave the weighted blanket a weight of 15 correct. What did I do here? Oh, I used this on both of them. I need to use the parameter absolute value and assign that there. That's much better. And there we have it. Now, why am I going through this whole big Simis? Well, the reason I'm doing this whole big Simis is let's go to here and to the assignments. And for the inheritance and polymorphism assignment. We're going to have an account which has a number and a balance. A savings account which inherits from account and adds a property. And a credit card account which inherits from account. And in fact, okay, that's interesting. Why is it not letting us open the image in a new tab? Cannot be displayed because it contains errors. Okay, let's try saving the image. And I'll put it here in the files. Where is it here? 204. Now we can see it. So, wow, this looks a lot like the thing with the blankets, doesn't it? We had the electric blanket and the weighted blanket, which were some classes of blankets. And here we have savings account and credit card account, which are some classes of the regular account. What we're going to do is we're going to write a program called test accounts that creates an array of five account objects. We'll have one regular account, one savings account, and three credit card accounts. Then you're going for each account, you're going to deposit $2,134 and withdraw $4782 and use two string. Now the two string method for a savings account does not include the calculated annual interest. The two string method for credit card account does not include the monthly payment. Instead, you're going to be using the calculate interest method for the savings account. And you're going to use the calculate payment method for the credit card account. But only if you have a savings account and only if you have a credit card account. In a similar way that in this example, I use the get efficiency only for electric blankets and comfort level only for weighted blankets. This should give you some idea of how these are parallel structures, so to speak. Oh, there's even some pseudo code here. Well, that sort of spoils the whole show, doesn't it? Let's go here and example files. Let's just open that up and see what it looks like. Couldn't hurt. Okay, that's for your main method. And this one, I am not using an enhanced for loop. I'm using a regular old for loop. If I wanted to use a regular old for loop here, then I would have said for it. I zero I less than blanket list dot length. I plus plus. In fact, let me save that as under different names that you'll have both of them for reference. I get less of a dot to string, I compile that and run it. I get exactly the same output. So that's using a regular old for loop instead of an enhanced for loop. And that is the mini lecture for tonight.