The objective of this module is to get hands-on experience with the following topics:
- Introduction to Abstraction
- Abstract classes and interfaces
- Access Modifiers (public, private, protected)
- Understand and implement packages in Java.
- Understand the import statement.
- Understand and implement access modifiers in Java.
Copy the classes from the previous lab to the appropriate packages com.trainingmug.ecommerce.service and com.trainingmug.ecommerce.main
-
Ensure that the necessary import statements are automatically generated by the IDE in
Main.java,Payroll.java, andPayrollImpl.java.Example:
Main.javapackage com.trainingmug.ecommerce.main; import com.trainingmug.ecommerce.Designer; import com.trainingmug.ecommerce.Developer; import com.trainingmug.ecommerce.Employee; import com.trainingmug.ecommerce.service.PayrollImpl;
Hint: If you are unable to see them, expand the code at line 3.
-
In
Employee.javamake the following changes:- Make all instance variables and static variables private.
- Make the no-argument constructor
Employee()public. - Make all methods public.
- Generate
getter()andsetter()methods for all instance and static variables.
-
In
Developer.javamake the following changes:- Make
noOfProjectsprivate. - Make all methods public.
- Generate
getter()andsetter()methods for thenoOfProjectsproperty. - To remove errors when accessing properties directly, use getter methods.
Example:empId -> getEmpId(),name -> getName().
- Make
-
In
Designer.javamake the following changes:- Make
noOfWebsitesprivate. - Make all methods public.
- Generate
getter()andsetter()methods for thenoOfWebsitesproperty. - To remove errors when accessing properties directly, use getter methods.
Example:empId -> getEmpId(),name -> getName().
- Make
-
In
Main.java:- Remove the statements that access properties on
employee1andemployee2objects directly. - Hint: Make sure to save the files. All errors should now be resolved.
- Remove the statements that access properties on
-
Run
Main.javaand observe that the output is the same as in the previous lab, but with properly implemented Object-Oriented Programming (OOP) principles.