Now, the thing is all the stuff is good but you really have to be doing some in-depth design of classes for a lot of it to make sense. So right now, it's like a lot of rules for kids, and then unfortunately, the shopping cart example really didn't do it for me. I'm going to walk you through it because we're actually going to come back to this in the next module, so you need to spend some time getting to know it. I'm just saying I think that, unfortunately, by the end of the day, working through this particular programming challenge, it would be really hard to know if your kids really understood what they did. They could follow all the instructions possibly but not know what it is. All right. This is going to take awhile, so take a deep breath. Our shopping cart class. It's basically got three instance variables. An array list of items, think about a shopping cart on Amazon. You've got items that are in there, your total amount that you're spending, and then there's going to be this weird thing which totally is not explained, internal discount. Even at the end of this I still don't know what internal discount really means. Item, remember, we've seen item before. We've had item and discounted item was the subclass of item. We're coming back to that. So they give you a Repl.it link, which I recommend going to, and they strongly recommend going to, and so that comes up and it shows you Main first. I'm like, "Okay. It's always a good place to start." I'm like, "Okay, we make a shopping cart." Yes, I went on to Amazon, I clicked onto my shopping cart and then I can add some items to it, a new item named "bread" and I'm assuming that's the price and do item milk and that's the price, okay. Apparently, I can print the order. Okay, that seems reasonable. But there's three other files in this Repl.it, which contributes to the confusion. Now, what do I look at next? Well, if I go back to Main, I had a shopping cart there. So I'm like, "Well, I better start by understanding what shopping cart is." So I'll click on ShoppingCart.java and let's go explore that code. I'm going to go through at multiple pages here. We've got a shopping cart, which is an array list of item order. I previewed that already. I've got a constructor there. That looks pretty normal, got it. I've got an add method. Maybe I should pay attention to that. So if I'm going to add an item, first, I'm going to add it to my order, that's that array list, that makes sense, and then I'm also going to update my total bill so far by getting the price. This is one of the first places I start gritting my teeth. Instanceof is not covered in AP CSA. As far as I know we used it maybe once before but we certainly didn't explain it and I was like, "Don't worry about it." So if i is an instance of a discount item, what this allows you to do? So remember Item is a superclass, discounted item is a subclass. Variable name instanceof class name basically checks to see if that item was constructed using the subclass name; discounted item in this case, or was it constructed using Item. If it was constructed using discounted item, this whole thing will return true. This is actually a really great use of subclasses and whatever, except we're not covering it for AP CSA and it isn't really described in anywhere and that really bothers me. Then what's even weirder is this weird cast of i to discounted item in order to be able to called getDiscount. This is required and we're not going to explain it for at least for the next section, maybe in the section after that. This is because the getDiscount method only exists in discounted item. We have to force Java to say, "You know what? I'm telling you, i variable, that's of discounted item type, so they can go on and find that method." Do you remember what the purpose was in doing this assignment yet anyway? I'm not really sure if I do. Then, worse, let's remember, I'm in a shopping cart. I thought a shopping cart was a good one to look into because that was the first thing I declared and there's all these print methods, print or toStrings or things, and I started looking at them and made my head hurt. I was just like, "Do I need to know all of this? What's going on?" I don't think you actually really need to understand any of the code in any of them. But that was not told to us. So as a student, I'd probably just throw it away. I probably just throw my hands up anyway, but I had to keep going to be able to explain it to you. So at that point, I give up on looking at ShoppingCart.java. I'm like, "Whatever, it's not worth my time to do investment until I know I absolutely have to." So I go back to the question and it says, "What you're going to do is work in the discountedItem subclass." I'm like, "Oh, every bullet point is under that. So hopefully, I'm just going to be working in discounted item, but they did give me a hint it's a subclass, so I better look at Item so that I can understand the relationships." That's probably going to be important. So I go into Item.java. It's not too bad. All items that I would buy on Amazon, whatever, have a string name and a double price. Those seem like reasonable instance variables. I got a couple of constructors here that look very normal, and I've got an accessor for the price at least. Then, there's another one of these things, valueToString things and I'm looking at it and it's like, "What was the absolute value got to do with anything? Why isn't it using the result which is a string in that link? " Again, I didn't actually ever bothered to figure this out, although I'm pretty sure this is doing some pretty printing to make sure I have a dollar sign in front of it and that whenever you have like $15.10, it doesn't come out 15.1, it comes up 15.10. Like really, really darn sure that's what it's doing but I still didn't want to actually go and look at everything to make sure I was right about that. Your students don't need to look at it at all. Okay. Well, looking at Item was maybe helpful and still a little bit more teeth-gritting, so let's go back and just follow the darn instructions here. DiscountedItem subclass, I need to add an instance variable for the discount amount and add constructor that call super. I think I can do that. This is the original DiscountedItem.java that they've got for us. It's got nice comments in there, so as a student I can follow through. Let me do those first two steps. I'm going to add an instance variable of type double called discount. It told me to actually and said, "Add constructors," and I looked into Item and I saw that they had a default one with nothing. So I made a default one and I called it my super constructor. You have to have a default map. I probably need to set the discount there, maybe to zero? I should have set the discount to zero. That's my bad. Then in the DiscountedItem constructor that I looked in Item and again, it took a name and a price, so I added on the discount, I call super to get the name the price, and then I set the discount to disc. Next one, add the get/set methods for discount, just that one instance variable. That's not going to involve any crazy inheritance things because discount only belongs to the subclass, this is a specialization. So that's the gets method given there for you. I don't exactly remember why, but you need to modify it because right now they're just add it to return zero. So these are very simple getDiscount, return your discount, setDiscount take a parameter and change your discount. Then I'm already worried, toString. When I went through shopping class, cart, and Item, whenever I got to a toString, I was left confused, so I'm worried. Luckily, it actually spills out everything that I'm supposed to do, but I'm going to have to pick it apart and, in the end, sort of get it because it's weird. It says you should call the superclass so it prints out the item amount just fine, and then put your discount afterwards in a parentheses with a minus sign. That's not something I'm used to, so given I'm already confused, this is weird. So go into DiscountedItem.java, they has the comment there that tells you, it says, "Add it toString method that returns a call to the super toString." Okay. Even if I don't know what the heck I'm doing, I can do that. So I like that part that's not in the box "return super.toString." That's basically when we're taking care of inheritance saying, "Look, I still don't understand how you print it out or it called toString for the Item class, but you know what? However you did it, do it here too." That's my generalization part. My specialization part is this discounted item it has a special part which is a discount, and then it says to call super.valueToString and send in the discount. So you know what? I type that in and it worked and it printed like it was supposed to. I still don't remember super.valueToString, that's going to go up into Item and print that. Why am I calling something my superclass that's about a discount? That makes no sense to me at all. It makes no sense to me at all. So I don't know. But I'm guessing valueToString remember, I think I said valueToString is just like a pretty print way of making sure you have whatever. So I think it's doing that, but again, at this point, if a student did this, I did this, I followed along, I did exactly what it said. Do I know what I just did? I'm not really convinced that I do, and I think either some good more explanation will be needed around that or whatever, but I don't really think it really reinforced me for me about using super in my inheritance. We've actually done that before too, and we're only working with two levels of inheritance here, not an entire hierarchy, so it's a little bit of a teeth grinder for me. Maybe you'll like it better.