-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStuff.java
More file actions
79 lines (66 loc) · 2.44 KB
/
Stuff.java
File metadata and controls
79 lines (66 loc) · 2.44 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package typeinfo;
import java.util.*;
/**
* RUN:
* javac typeinfo/Stuff.java && java typeinfo.Stuff
* OUTPUT:
* [Position: President Person: Me Last The Top, Lonely At,
* Position: CTO NullPerson, Position: Marketing Manager NullPerson,
* Position: Project Lead Person: Janet Planner The Burbs,
* Position: Product Manager NullPerson,
* Position: Software Engineer Person: Bob Coder Bright Light City,
* Position: Software Engineer NullPerson,
* Position: Software Engineer NullPerson,
* Position: Software Engineer NullPerson,
* Position: Test Engineer NullPerson,
* Position: Technical Writer NullPerson]
*/
public class Stuff extends ArrayList<Position> {
public void add(String title, Person person) {
add(new Position(title, person));
}
public void add(String... titles) {
for (String title : titles) {
add(new Position(title));
}
}
public Stuff(String... titles) {
add(titles);
}
public boolean positionAvailable(String title) {
for (Position position : this) {
if (position.getTitle().equals(title) &&
position.getPerson() == Person.NULL)
{
return true;
}
}
return false;
}
public void fillPosition(String title, Person hire) {
for (Position position : this) {
if (position.getTitle().equals(title) &&
position.getPerson() == Person.NULL)
{
position.setPerson(hire);
return;
}
}
throw new RuntimeException("Position " + title + " not awailable");
}
public static void main(String[] args) {
Stuff staff = new Stuff(
"President", "CTO", "Marketing Manager", "Project Lead"
, "Product Manager", "Software Engineer"
, "Software Engineer", "Software Engineer"
, "Software Engineer", "Test Engineer"
, "Technical Writer"
);
staff.fillPosition("President", new Person("Me", "Last", "The Top, Lonely At"));
staff.fillPosition("Project Lead", new Person("Janet", "Planner", "The Burbs"));
if (staff.positionAvailable("Software Engineer")) {
staff.fillPosition("Software Engineer", new Person("Bob", "Coder", "Bright Light City"));
}
System.out.println(staff);
}
}