0
2.5kviews
Write a program to read and display the details of ten employees

Write a program to read and display the details of ten employees with the following specifications:

Data Members: Emp_id, Emp_name, Emp_salary

Parameterized constructors to initialize data members of Employees and member functions:

Display() :- To display information of all employees.

Mumbai University > Information Technology > Sem 3 > Object Oriented Programming Methodology

Marks: 10M

Year: May 2015

1 Answer
0
11views
import java.io.*;
class Employee {
    int Emp_id;
    String Emp_name;
    int Emp_salary;

    Employee(int empid, String empname, int empsalary) {
        Emp_id = empid;
        Emp_name = empname;
        Emp_salary = empsalary;
    }

    void display() {
        System.out.println("ID: "+this.Emp_id + " Name: "+this.Emp_name + " Salary:" + this.Emp_salary);
    }

    public static void main(String args[]) throws IOException {
        Employee e[] = new Employee[10];
        for(int i=0; i<10; i++){
            System.out.println("Enter the ID, Name and Salary of Employee("+ (i+1) +")");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int Emp_id = Integer.parseInt(br.readLine());
            String Emp_name = br.readLine();
            int Emp_salary = Integer.parseInt(br.readLine());
            e[i] = new Employee(Emp_id, Emp_name, Emp_salary);
        }
        System.out.println("Employee Details: \n-------------------");
        for(int i=0; i<10; i++){
            e[i].display();
        }

    }
}

OUTPUT

Enter the ID, Name and Salary of Employee(1)

1

Arvind

10000

Enter the ID, Name and Salary of Employee(2)

2

Bala

15000

Enter the ID, Name and Salary of Employee(3)

3

Chetan

4500

Enter the ID, Name and Salary of Employee(4)

4

Dinesh

18000

Enter the ID, Name and Salary of Employee(5)

5

Eve

32000

Enter the ID, Name and Salary of Employee(6)

6

farzana

12000

Enter the ID, Name and Salary of Employee(7)

7

ganesh

15000

Enter the ID, Name and Salary of Employee(8)

8

hansa

24000

Enter the ID, Name and Salary of Employee(9)

9

indrajeet

11000

Enter the ID, Name and Salary of Employee(10)

10

kunal

7000

Employee Details:

$-----------$

ID: 1 Name: Arvind 10000

ID: 2 Name: Bala 15000

ID: 3 Name: Chetan 4500

ID: 4 Name: Dinesh 18000

ID: 5 Name: Eve 32000

ID: 6 Name: farzana 12000

ID: 7 Name: ganesh 15000

ID: 8 Name: hansa 24000

ID: 9 Name: indrajeet 11000

ID: 10 Name: kunal 7000

Please log in to add an answer.