From the course: Oracle Java Foundations

Unlock this course with a free trial

Join today to access over 24,000 courses taught by industry experts.

Flow control: Demo

Flow control: Demo

(cheerful tones) - [Instructor] Exercise 4-1: Using the switch statement. In this exercise we'll add a string property called size to the customer class. We'll use the customer in the main method of the shop app. In the main method of the shop class, we'll set the size property for the customer, Pinky. We'll place this logic after the initialization of the customer name and we'll set the customer size to be S. We'll create a measurement variable of type int, and set it to the value of three. We'll add a switch statement that derives the customer size based on a measurement value. In case of measurement values, one, two, or three, the size will be S. If it's four, five or six, it'll be M. Seven, eight, nine, it'll be L for large. And in all their cases, the size of the customer should be X. Let's get started. First we're going to add a string property called size to the customer class. So off we go to the customer class and we'll add a string size. Now, we're doing this for convenience…

Contents