From the course: Oracle Java Foundations
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Scope and access: Demo 2 - Java Tutorial
From the course: Oracle Java Foundations
Scope and access: Demo 2
(bright music) - [Joe] Exercise 5-2: Overload a method. We're going to add a new method to the Customer class called setSize. It'll be similar to the existing setSize method, except it'll accept an integer measurement parameter instead of a String. Let's go do that first. So we need to come over to the Customer class and grab setSize. So here's your Customer class, here's your setSize. And we're going to create another method. So we're going to do the same signature, basically, or same definition, public void setSize. But now, it's going to take an int size in this case, and then our curly braces. So now, it will take an int measurement parameter instead of a String. We're now going to move the switch statement from the main method into this new method and use the switch code to determine the size. So we go back to ShopApp and we take the switch statement, which is all of this right here. And I'm going to do Ctrl + X to take it out. Go back to Customer, and do a Ctrl + V to put it in.…