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.
Objects: Demo 1 - Java Tutorial
From the course: Oracle Java Foundations
Objects: Demo 1
(gentle music) - [Instructor] Exercise 5-3: Associate Customer with Clothing. We have a customer class, and we have a clothing class, and we'd like to create a relationship between the two such that a customer can keep track of the items of clothing that they purchased. So we're going to add a private instance variable called items to the customer class to store an array of clothing objects that the customer has. We'll provide a public method called addItems in the customer class that accepts clothing arrays as an argument and assigns it to the items instance. So we're going to have an addItems method, and we'll have a public method in the customer class that returns an array of the clothing items. So what this allows us to do is addItems into the array by using the customer, and then be able to get that array back out to print with it or do calculations. We're then going to provide a public method called getTotalClothingCost in the customer class that calculates and returns the total…