-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver_2.java
More file actions
61 lines (53 loc) · 1.6 KB
/
Driver_2.java
File metadata and controls
61 lines (53 loc) · 1.6 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
58
59
60
61
package driver_2;
import java.util.*;
public class Driver_2 {
public static void main(String[] args) {
Employee emp[] = new Employee[100];
Employee hold;
Scanner input = new Scanner(System.in);
int count = 0;
System.out.println("Enter name - 'quit' to stop");
String name = input.next();
while (!name.equals("quit")) {
System.out.println("Enter age ");
int age = input.nextInt();
System.out.println("Enter salary ");
double salary = input.nextDouble();
emp[count++] = new Employee(name, age, salary);
System.out.println("Enter name - quit to stop");
name = input.next();
}
for(int pass = 1; pass < count ; pass++) {
for(int i = 0 ; i < count - 1; i++) {
if(emp[i].getName().compareTo(emp[i+1].getName()) > 0) {
hold = emp[i];
emp[i] = emp[i + 1];
emp[i + 1] = hold;
}
}
}
for(int i = 0; i < count ; i++)
System.out.println(emp[i].toString());
System.out.println();
for(int i = 0; i < count ; i++) {
if(emp[i].getSalary() > 40000 && emp[i].getSalary() < 60000)
System.out.println(emp[i].toString_1());
}
}
}
class Employee{
private String name;
private int age;
private double salary;
public Employee(String n, int a, double s) {
name = n; age = a; salary = s;
}
public String getName() {return name;}
public double getSalary() {return salary;}
public String toString() {
return "name: " + name + " age: " + age + " salary: $" + salary;
}
public String toString_1() {
return name + " has a salary between 40k and 60k." + "\n";
}
}