Skip to content

This lab gives you the hands-on experience on working on Encapsulation Feature in Java and familiar with access modifiers like public, private, protected and default

Notifications You must be signed in to change notification settings

trainingmug-edu/java-encapsulation-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module 3: Abstraction & Encapsulation

Objective

The objective of this module is to get hands-on experience with the following topics:

  1. Introduction to Abstraction
  2. Abstract classes and interfaces
  3. Access Modifiers (public, private, protected)

Lab 3.2

Objectives

  1. Understand and implement packages in Java.
  2. Understand the import statement.
  3. Understand and implement access modifiers in Java.

Problem Statement

Copy the classes from the previous lab to the appropriate packages com.trainingmug.ecommerce.service and com.trainingmug.ecommerce.main

Tasks

  1. Ensure that the necessary import statements are automatically generated by the IDE in Main.java, Payroll.java, and PayrollImpl.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.

  2. 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() and setter() methods for all instance and static variables.
  3. In Developer.java make the following changes:

    • Make noOfProjects private.
    • Make all methods public.
    • Generate getter() and setter() methods for the noOfProjects property.
    • To remove errors when accessing properties directly, use getter methods.
      Example: empId -> getEmpId(), name -> getName().
  4. In Designer.java make the following changes:

    • Make noOfWebsites private.
    • Make all methods public.
    • Generate getter() and setter() methods for the noOfWebsites property.
    • To remove errors when accessing properties directly, use getter methods.
      Example: empId -> getEmpId(), name -> getName().
  5. In Main.java:

    • Remove the statements that access properties on employee1 and employee2 objects directly.
    • Hint: Make sure to save the files. All errors should now be resolved.
  6. 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.

About

This lab gives you the hands-on experience on working on Encapsulation Feature in Java and familiar with access modifiers like public, private, protected and default

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages