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.java
package 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.java
make 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.java
make the following changes:- Make
noOfProjects
private. - Make all methods public.
- Generate
getter()
andsetter()
methods for thenoOfProjects
property. - To remove errors when accessing properties directly, use getter methods.
Example:empId -> getEmpId()
,name -> getName()
.
- Make
-
In
Designer.java
make the following changes:- Make
noOfWebsites
private. - Make all methods public.
- Generate
getter()
andsetter()
methods for thenoOfWebsites
property. - 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
employee1
andemployee2
objects directly. - Hint: Make sure to save the files. All errors should now be resolved.
- Remove the statements that access properties on
-
Run
Main.java
and observe that the output is the same as in the previous lab, but with properly implemented Object-Oriented Programming (OOP) principles.