Skip to content

Commit 5895d6a

Browse files
committed
first commit
0 parents  commit 5895d6a

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

Chief.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
enum Position {
2+
CEO,
3+
CTO,
4+
CFO
5+
}
6+
7+
public class Chief extends Employee {
8+
9+
Position position;
10+
11+
Chief(String name, Position position) {
12+
super(name);
13+
this.position = position;
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return super.toString() + ", Chief: " + position;
19+
}
20+
}

Company.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.ArrayList;
2+
3+
public class Company {
4+
5+
int nEmployees = 0;
6+
ArrayList<Employee> employees = new ArrayList<>();
7+
8+
Company() {
9+
}
10+
11+
void hireEmployee(Employee employee) {
12+
int id = nEmployees++;
13+
employee.setId(id);
14+
employee.setActive(true);
15+
employees.add(employee);
16+
}
17+
18+
boolean fireEmployee(int id) {
19+
for (int i = 0; i < this.employees.size(); i++) {
20+
Employee e = this.employees.get(i);
21+
if (e.getId() == id) {
22+
e.setActive(false);
23+
return true;
24+
}
25+
}
26+
return false;
27+
}
28+
29+
void listActiveEmployees() {
30+
for (int i = 0; i < this.employees.size(); i++) {
31+
Employee e = this.employees.get(i);
32+
System.out.println(e);
33+
}
34+
}
35+
36+
}

Employee.java

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.util.Date;
2+
3+
public class Employee {
4+
private int id;
5+
private String name;
6+
private boolean active;
7+
private long[] attendance;
8+
9+
Employee(String name) {
10+
this.name = name;
11+
}
12+
13+
public int getId() {
14+
return id;
15+
}
16+
17+
public void setId(int id) {
18+
this.id = id;
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public void setName(String name) {
26+
this.name = name;
27+
}
28+
29+
public boolean isActive() {
30+
return active;
31+
}
32+
33+
public void setActive(boolean active) {
34+
this.active = active;
35+
}
36+
37+
public void addAttendance() {
38+
this.attendance[this.attendance.length] = new Date().getTime();
39+
}
40+
41+
public void listAttendances() {
42+
System.out.println("==== " + this.name + "Attendance ===");
43+
for (int i = 0; i < this.attendance.length; i++) {
44+
System.out.println();
45+
}
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return "id: " + this.id + ", name: " + this.name;
51+
}
52+
}

Main.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
if (args.length > 0) {
4+
if (args[0].equals("ex1")) {
5+
Company company = new Company();
6+
Employee e1 = new Employee("Joao");
7+
Employee e2 = new Employee("Manel");
8+
company.hireEmployee(e1);
9+
company.hireEmployee(e2);
10+
Chief c1 = new Chief("Antonio", Position.CEO);
11+
company.hireEmployee(c1);
12+
company.listActiveEmployees();
13+
} else if (args[0].equals("ex2")) {
14+
System.out.println("ex2");
15+
} else {
16+
System.out.println("default");
17+
}
18+
} else {
19+
int a = 1;
20+
float b = (float) 1.1;
21+
boolean c = true;
22+
char d = '\n';
23+
}
24+
}
25+
}

README.md

24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)