Skip to content

Commit c8b02a0

Browse files
committed
add more examples
1 parent 5895d6a commit c8b02a0

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

Company.java

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ boolean fireEmployee(int id) {
2626
return false;
2727
}
2828

29+
void listAttendances() {
30+
for (int i = 0; i < this.employees.size(); i++) {
31+
Employee e = this.employees.get(i);
32+
e.listAttendances();
33+
}
34+
}
35+
2936
void listActiveEmployees() {
3037
for (int i = 0; i < this.employees.size(); i++) {
3138
Employee e = this.employees.get(i);

Employee.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import java.util.Date;
2+
import java.util.ArrayList;
23

34
public class Employee {
45
private int id;
56
private String name;
67
private boolean active;
7-
private long[] attendance;
8+
private ArrayList<Date> attendance = new ArrayList<>();
89

910
Employee(String name) {
1011
this.name = name;
@@ -35,13 +36,13 @@ public void setActive(boolean active) {
3536
}
3637

3738
public void addAttendance() {
38-
this.attendance[this.attendance.length] = new Date().getTime();
39+
this.attendance.add(new Date());
3940
}
4041

4142
public void listAttendances() {
42-
System.out.println("==== " + this.name + "Attendance ===");
43-
for (int i = 0; i < this.attendance.length; i++) {
44-
System.out.println();
43+
System.out.println("==== " + this.name + "'s Attendance ===");
44+
for (int i = 0; i < this.attendance.size(); i++) {
45+
System.out.println(this.attendance.get(i));
4546
}
4647
}
4748

Main.java

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
import java.util.Date;
2+
3+
14
public class Main {
25
public static void main(String[] args) {
36
if (args.length > 0) {
47
if (args[0].equals("ex1")) {
8+
Company company = new Company();
9+
Employee e1 = new Employee("Joao");
10+
Employee e2 = new Employee("Manel");
11+
company.hireEmployee(e1);
12+
company.hireEmployee(e2);
13+
company.listActiveEmployees();
14+
} else if (args[0].equals("ex2")) {
515
Company company = new Company();
616
Employee e1 = new Employee("Joao");
717
Employee e2 = new Employee("Manel");
@@ -10,16 +20,35 @@ public static void main(String[] args) {
1020
Chief c1 = new Chief("Antonio", Position.CEO);
1121
company.hireEmployee(c1);
1222
company.listActiveEmployees();
13-
} else if (args[0].equals("ex2")) {
14-
System.out.println("ex2");
23+
} else if (args[0].equals("ex3")) {
24+
Company company = new Company();
25+
Employee e1 = new Employee("Joao");
26+
Employee e2 = new Employee("Manel");
27+
company.hireEmployee(e1);
28+
company.hireEmployee(e2);
29+
Chief c1 = new Chief("Antonio", Position.CEO);
30+
company.hireEmployee(c1);
31+
32+
e1.addAttendance();
33+
e1.addAttendance();
34+
e1.addAttendance();
35+
e2.addAttendance();
36+
e2.addAttendance();
37+
e2.addAttendance();
38+
c1.addAttendance();
39+
e1.addAttendance();
40+
41+
company.listAttendances();
1542
} else {
16-
System.out.println("default");
43+
System.out.println("Invalid example");
1744
}
1845
} else {
19-
int a = 1;
20-
float b = (float) 1.1;
21-
boolean c = true;
46+
String a = "Hello World";
47+
int b = 1;
48+
float c = (float) 1.1;
2249
char d = '\n';
50+
boolean e = true;
51+
System.out.println(a);
2352
}
2453
}
2554
}

README.md

216 Bytes

��# WS-Java

WS-Java

Compile

$ javac *.java

Run

$ java Main

Clean

$ rm *.class

0 commit comments

Comments
 (0)