0% found this document useful (0 votes)
6 views6 pages

Oop Activity Saad 21414

The document outlines a programming assignment for a class on Object Oriented Programming, requiring the creation of three classes: Employee, Manager (inheriting from Employee), and Project (inheriting from Manager). Each class includes methods for inputting and printing data, demonstrating function overloading, and the main class creates an object of Project to showcase the functionality. The code provided illustrates the structure and behavior of these classes, including example output for user input.

Uploaded by

bm6775893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Oop Activity Saad 21414

The document outlines a programming assignment for a class on Object Oriented Programming, requiring the creation of three classes: Employee, Manager (inheriting from Employee), and Project (inheriting from Manager). Each class includes methods for inputting and printing data, demonstrating function overloading, and the main class creates an object of Project to showcase the functionality. The code provided illustrates the structure and behavior of these classes, including example output for user input.

Uploaded by

bm6775893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF SOFTWARE ENGINEERING

NATIONAL UNIVERSITY OF MODERN LANGUAGES

NAME:
SAAD CHEEMA

NUML ID:
NUML-F24-21414

CLASS:
BSIT-2 MORNING

COURSE:
OBJECT ORIENTED PROGRAMMING
(THEROY)

SUBMITTED TO:
MS. SOBIA YOUSAF

CLASS ACTIVITY NO:


01
QUESTION NO.01:
Write a class Employee.
Write another class manager inherited from Employee.
Write another class project inherited from Manager.
QUESTION NO.02:
Write required data members, write two functions in each class input data() and print
data(). For each class these functions will take input and print their attributes use
function overloading. Create an object of class project and demonstrate working.

class Employee {
String name;
int age;
double salary;

// Function to input employee data


public void inputData() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Employee Name: ");
name = sc.nextLine();
System.out.print("Enter Employee Age: ");
age = sc.nextInt();
System.out.print("Enter Employee Salary: ");
salary = sc.nextDouble();
}

// Function to print employee data


public void printData() {
System.out.println("Employee Name: " + name);
System.out.println("Employee Age: " + age);
System.out.println("Employee Salary: " + salary);
}
}

// Derived class Manager from Employee


class Manager extends Employee {
String department;

// Function to input manager data (inherited from Employee + additional data)


@Override
public void inputData() {
super.inputData(); // Input from base class (Employee)
Scanner sc = new Scanner(System.in);
System.out.print("Enter Manager Department: ");
department = sc.nextLine();
}

// Function to print manager data


@Override
public void printData() {
super.printData(); // Print from base class (Employee)
System.out.println("Manager Department: " + department);
}
}

// Derived class Project from Manager


class Project extends Manager {
String projectName;
double projectBudget;

// Function to input project data (inherited from Manager)


@Override
public void inputData() {
super.inputData(); // Input from base class (Manager)
Scanner sc = new Scanner(System.in);
System.out.print("Enter Project Name: ");
projectName = sc.nextLine();
System.out.print("Enter Project Budget: ");
projectBudget = sc.nextDouble();
}

// Function to print project data


@Override
public void printData() {
super.printData(); // Print from base class (Manager)
System.out.println("Project Name: " + projectName);
System.out.println("Project Budget: " + projectBudget);
}
}

public class Main {


public static void main(String[] args) {
// Create an object of the Project class
Project project = new Project();
// Input data for the project
project.inputData();

// Print all the data (Employee, Manager, Project)


System.out.println("\n----- Project Data -----");
project.printData();
}
}
```

Explanation of the Code:


1. Class Employee:
- Contains attributes like name, age, and salary.
- The method inputData() uses Scanner to input data from the user.
- The method printData() prints the employee’s information.

2. Class Manager:
- Inherits from the Employee class and adds a new attribute department.
- The inputData() method calls the super.inputData() method to get the
employee’s data and then asks for the manager's department.
- The printData() method calls super.printData() to print employee data and adds
the manager’s department.

3. Class Project:
- Inherits from Manager and adds attributes for the project: projectName and
projectBudget.
- The inputData() method calls super.inputData() to get the data from both the
employee and manager classes, then asks for the project-specific data.
The printData() method calls super.printData() to print all the inherited data and
adds the project-specific data.
4. Main Class (Main):
- In the main() method, an object project of the Project class is created.
- The inputData() method is called to take input for all the attributes.
- The printData() method is then called to display the input data.

Example Output:
Enter Employee Name: John
Enter Employee Age: 35
Enter Employee Salary: 50000
Enter Manager Department: IT
Enter Project Name: Web Development
Enter Project Budget: 200000

----- Project Data -----


Employee Name: John
Employee Age: 35
Employee Salary: 50000.0
Manager Department: IT
Project Name: Web Development
Project Budget: 200000.0

You might also like