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.

Scope and access: Demo 1

Scope and access: Demo 1 - Java Tutorial

From the course: Oracle Java Foundations

Scope and access: Demo 1

(upbeat music) - [Instructor] "Exercise 5-1: Apply Encapsulation." In this exercise, we'll encapsulate all variables for all variables in both Customer and Clothing class, and provide accessor methods called getters and setters for those variables. We'll use the Insert Code context menu to generate getter and setter methods. We'll make sure to select "Encapsulate Fields," which will replace the individual reference with a method reference. NetBeans will replace all the direct Clothing and Customer variable references in the main method with the corresponding set and get method invocations. Then we'll add two constants to the Clothing class to represent minimum price and tax rate. We'll add logic to the setPrice method to ensure price is never smaller than the minimum value. We'll add logic to the getPrice method to automatically add tax, and then we can remove the line of code that adds tax to price when calculating the total value. Okay, so first of all, we need to encapsulate the…

Contents