Page 484 - computer science (868) class 11
P. 484
Program 17 Define a class Employee to input the details of the employee and print them. The data
members and member methods are defined as follows:
Data Members
int Id : to store the employee ID
String Name : to store the employee name
long Salary : to store the employee salary
Member Methods
void getData() : to enter the details of the employee such as name, ID, age and
salary
void display() : to display the details of the employee
Specify the class Employee by giving details of the constructors and also write the main
function.
1 import java.util.*;
2 class Employee
3 {
4 int Id;
5 String Name;
6 int Age;
7 long Salary;
8
9 void getData() // Defining GetData()
10 {
11 Scanner sc = new Scanner(System.in);
12 System.out.print("\n\tEnter Employee Id : ");
13 Id = sc.nextInt();
14 System.out.print("\n\tEnter Employee Name : ");
15 Name = sc.nextLine();
16
17 System.out.print("\n\tEnter Employee Age : ");
18 Age = sc.nextInt();
19
20 System.out.print("\n\tEnter Employee Salary : ");
21 Salary = sc.nextLong();
22 }
482482 Touchpad Computer Science-XI

