-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_24.java
More file actions
57 lines (48 loc) · 1.63 KB
/
Practical_24.java
File metadata and controls
57 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Question := Write a program to create a class called Employee, having instance variables
like name, age, salary and empno. Initialize all the instance members using
constructor and empno should be auto generated by the program. Create an array
of objects to define 10 Employees.*/
import java.util.Scanner;
public class Practical_24 {
String name;
int age;
int emp_no = 1;
int salary;
public void getInput() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name := ");
name = sc.nextLine();
System.out.print("Enter the age := ");
age = sc.nextInt();
System.out.print("Enter the Salary := ");
salary = sc.nextInt();
}
public void display() {
System.out.println("Employee Name := " + name);
System.out.println("Employee Age := " + age);
System.out.println("Employee No. := " + emp_no);
System.out.println("Employee Salary := " + salary);
}
public static void main(String[] args) {
Practical_24[] pr = new Practical_24[10];
for(int i=0; i<10; i++) {
pr[i] = new Practical_24();
pr[i].getInput();
System.out.println("**** Data Entered as below ****");
pr[i].emp_no = pr[0].emp_no + i;
pr[i].display();
}
}
}
/*
Output :=
Enter the name := John
Enter the age := 24
Enter the Salary := 25000
**** Data Entered as below ****
Employee Name := John
Employee Age := 24
Employee No. := 1
Employee Salary := 25000
//upto 10 times...
*/