0% found this document useful (0 votes)
2 views

java_26

The document outlines a Java program that defines an 'Employee' class with subclasses 'Officer' and 'Manager'. It includes methods for displaying employee details and allows user input for creating instances of each class. The program successfully executes and displays the details of employees, officers, and managers based on user input.

Uploaded by

pankajajay080905
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java_26

The document outlines a Java program that defines an 'Employee' class with subclasses 'Officer' and 'Manager'. It includes methods for displaying employee details and allows user input for creating instances of each class. The program successfully executes and displays the details of employees, officers, and managers based on user input.

Uploaded by

pankajajay080905
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PROGRAM

import java.util.*;
class employee {
String Name; int Ph_no, Age, Salary;
String Address;
Scanner input=new Scanner(System.in);
employee(String name,int age,int ph_no,int salary,String address) {
Name=name;
Age=age;
Ph_no=ph_no;
Salary=salary;
Address=address;
}
void printsalary() {
System.out.println("Salary : "+Salary);
}
void display() {
System.out.println();
System.out.println("Name : "+Name);
System.out.println("Age : "+Age);
System.out.println("Phone : "+Ph_no);
System.out.println("Salary : "+Salary);
System.out.println("Address : "+Address);
}}
class officer extends employee {
String Sp;
officer(String name,int age,int ph_no,int salary,String address,String sp) {
super(name,age,ph_no,salary,address);
Sp=sp;
}
void display() {
Date : 11 /09/2024

PROGRAM NO: 26

PROGRAM TO DISPLAY DETAILS OF MEMBERS OF AN


ORGANISATION

AIM
To write a program which creates a class named 'Employee' having the following members:
Name, Age, Phone number, Address, Salary. It also has a method named print-Salary() which
prints the salary of the Employee. Two classes 'Officer' and ‘Manager' inherit the 'Employee'
class. The 'Officer' and "Manager' classes have data members 'specialization' and 'department'
respectively. Now assign name, age, phone number, address and salary to an officer and a
manager by making an object of both of these classes and print the same.
ALGORITHM
I. START
Class: employee
1. Declare instance variables 'Name' of type String, 'Age' of type int, 'Ph_no' of type
int, 'Salary' of type int, and 'Address' of type String.
2. Declare a Scanner object 'input' to read user input.
3. Define a parameterized constructor 'employee' with parameters 'String name', 'int
age', 'int ph_no', 'int salary', and 'String address'
a. Assign the values of 'name', 'age', 'ph_no', 'salary', and 'address' to the instance
variables.
4. Define a method 'printsalary' with no parameters
a. Display "Salary: " followed by the value of 'Salary'
5. Define a method 'display' with no parameters
a. Display a new line.
b. Display "Name: " followed by the value of 'Name'
c. Display "Age: " followed by the value of 'Age'
d. Display "Phone: " followed by the value of 'Ph_no'
e. Display "Salary: " followed by the value of 'Salary'
f. Display "Address: " followed by the value of 'Address'
System.out.println();
super.display();
System.out.println("Specialisation : "+Sp);
}}
class manager extends employee {
String Department;
manager(String name,int age,int ph_no,int salary,String address,String department) {
super(name,age,ph_no,salary,address);
Department=department;
}
void display() {
System.out.println();
super.display();
System.out.println("Department : "+Department);
}}
class organisation {
public static void main(String args[]) {
String Name;
int Age, Ph_no, Salary, n,x,y;
String Address;
String Sp;
String Department;
Scanner input=new Scanner(System.in);
System.out.print("Enter no of Employee : ");
n=input.nextInt();
employee e[]=new employee[n];
System.out.print("Enter no of Manager : ");
x=input.nextInt();
manager m[]=new manager[x];
System.out.print("Enter no of Officer : ");
y=input.nextInt();
officer o[]=new officer[y];
if (n>0) {
for (int i=0;i<n;i++) {
System.out.println("Employee Details");
System.out.print("Enter name : ");
Name=input.next();
System.out.print("Enter Age : ");
Class: officer extends employee
[The class officer will inherit the employee class]
1. Declare an instance variable 'Sp' of type String.
2. Define a parameterized constructor 'officer' with parameters 'String name', 'int age', 'int
ph_no', 'int salary', 'String address', and 'String sp'
a. Call the superclass constructor using 'super(name, age, ph_no, salary, address)'
b. Assign the value of 'sp' to the instance variable 'Sp'
3. Define a method 'display' with no parameters
a. Display a new line.
b. Call the superclass 'display' method using 'super.display()'
c. Display "Specialisation: " followed by the value of 'Sp'

Class: manager extends employee


[The class manager will inherit the employee class]
1. Declare an instance variable 'Department' of type String.
2. Define a parameterized constructor 'manager' with parameters 'String name', 'int age', 'int
ph_no', 'int salary', 'String address', and 'String department'
a. Call the superclass constructor using 'super(name, age, ph_no, salary, address)'
b. Assign the value of 'department' to the instance variable 'Department'
3. Define a method 'display' with no parameters
a. Display a new line.
b. Call the superclass 'display' method using 'super.display()'
c. Display "Department: " followed by the value of 'Department'
Age=input.nextInt();
System.out.print("Enter phone : ");
Ph_no=input.nextInt();
System.out.print("Enter Salary : ");
Salary=input.nextInt();
System.out.print("Enter Address : ");
Address=input.next();
e[i]=new employee(Name,Age,Ph_no,Salary,Address);
}}
if (y>0) {
for (int i=0;i<y;i++) {
System.out.println("Officer Details");
System.out.print("Enter name : ");
Name=input.next();
System.out.print("Enter Age : ");
Age=input.nextInt();
System.out.print("Enter phone : ");
Ph_no=input.nextInt();
System.out.print("Enter Salary : ");
Salary=input.nextInt();
System.out.print("Enter Address : ");
Address=input.next();
System.out.print("Enter Specialisation : ");
Sp=input.next();
o[i]=new officer(Name,Age,Ph_no,Salary,Address,Sp);
}}
if (x>0) {
for (int i=0;i<x;i++){
System.out.println("Manager Details");
System.out.print("Enter name : ");
Name=input.next();
System.out.print("Enter Age : ");
Age=input.nextInt();
System.out.print("Enter phone : ");
Ph_no=input.nextInt();
System.out.print("Enter Salary : ");
Salary=input.nextInt();
System.out.print("Enter Address : ");
Class: organisation
1. Define the main method
a. Declare local variables 'Name', 'Age', 'Ph_no', 'Salary', 'Address' of types String and int.
b. Declare local variables 'n', 'x', and 'y' of type int.
c. Declare local variables 'Sp' and 'Department' of type String.
d. Create an array of 'employee' objects named 'e' with a size of 'n'.
e. Create an array of 'manager' objects named 'm' with a size of 'x'.
f. Create an array of 'officer' objects named 'o' with a size of 'y'.
g. Display "Enter no of Employee: "
h. Read the number of employees 'n' from the user.
i. Display "Enter no of Manager: "
j. Read the number of managers 'x' from the user.
k. Display "Enter no of Officer: "
l. Read the number of officers 'y' from the user.
m. Use a conditional statement to check if 'n' is greater than 0
i. Use a for loop to iterate from 0 to 'n'
- Display "Employee Details"
- Read employee details from the user and create an object 'e[i]' of type 'employee'
n. Use a conditional statement to check if 'y' is greater than 0
i. Use a for loop to iterate from 0 to 'y'
- Display "Officer Details"
- Read officer details from the user and create an object 'o[i]' of type 'officer'
o. Use a conditional statement to check if 'x' is greater than 0
i. Use a for loop to iterate from 0 to 'x'
- Display "Manager Details"
- Read manager details from the user and create an object 'm[i]' of type 'manager'
p. Use a for loop to iterate over 'o' and call the 'display' method on each officer object.
q. Use a for loop to iterate over 'm' and call the 'display' method on each manager object
r. Use a for loop to iterate over 'e' and call the 'display' method on each employee object

II. END
Address=input.next();
System.out.print("Enter Department : ");
Department=input.next();
m[i]=new manager(Name,Age,Ph_no,Salary,Address,Department);
}}
for (int i=0;i<y;i++)
o[i].display();
for (int i=0;i<x;i++)
m[i].display();
for (int i=0;i<n;i++)
e[i].display();
}}

OUTPUT

Enter no of Employee : 0
Enter no of Manager : 1
Enter no of Officer : 1
Officer Details
Enter name : Serah
Enter Age : 23
Enter phone : 987868686
Enter Salary : 23000
Enter Address : efgh
Enter Specialisation : Communication
Manager Details
Enter name : Rohit
Enter Age : 33
Enter phone : 913579246
Enter Salary : 1500000
Enter Address : ijklm
Enter Department : HR
Name : Sera
Age : 23
Phone : 987868686
Salary : 23000
Address : efgh
Specialisation : Communication
Name : Rohit
Age : 33
Phone : 913579246
Salary : 1500000
Address : ijklm
Department : HR
RESULT
The program is successfully executed, and the output is obtained.

You might also like