-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
51 lines (46 loc) · 1.54 KB
/
Employee.java
File metadata and controls
51 lines (46 loc) · 1.54 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
import java.util.Scanner;
public class Employee {
int id;
String name;
String c_name;
int sal;
public Employee(String c_name, String name, int id, int sal) {
this.id = id;
this.name = name;
this.c_name = c_name;
this.sal = sal;
}
public static void result(Employee tarr[])
{
int maxsal1= Integer.MIN_VALUE , maxsal2= Integer.MIN_VALUE;
int Aindex=0, Bindex=0;
for (int i = 0; i <tarr.length ; i++) {
if (tarr[i].c_name.equals("A") && tarr[i].sal > maxsal1) {
maxsal1 = tarr[i].sal;
Aindex = i;
}
if (tarr[i].c_name.equals("B") && tarr[i].sal > maxsal2) {
maxsal2 = tarr[i].sal;
Bindex = i;
}
}
System.out.println("The Employee name is = "+ tarr[Bindex].name + " sal = "+ tarr[Bindex].sal+ " Commpany name = "+ tarr[Bindex].c_name);
System.out.println("The Employee name is = "+ tarr[Aindex].name + " sal = "+ tarr[Aindex].sal+ " Commpany name = "+ tarr[Aindex].c_name);
}
}
class EmployeeTest
{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("How many objects you want to create");
int size= s.nextInt();
Employee arr[] = new Employee[size];
for (int i = 0; i <arr.length ; i++) {
System.out.println("enter companyname, employeename, id, salary");
// creating object by using the new and initializing object by
// using the parameterized constructor
arr[i] = new Employee(s.next(),s.next(),s.nextInt(),s.nextInt());
}
Employee.result(arr);
}
}