-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterview.java
More file actions
76 lines (65 loc) · 2.08 KB
/
Copy pathInterview.java
File metadata and controls
76 lines (65 loc) · 2.08 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
package interviews;
import java.util.HashSet;
import java.util.Set;
public class Interview implements IInterview {
// #region members
protected int id;
protected String name;
protected String description;
protected int duration; // number of minuts
protected Set<Question> questions;
// #endregion
// #region getters
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public int getDuration() {
return duration;
}
public Set<Question> getQuestions() {
return questions;
}
// #endregion
// #region contructors
public Interview(int id, String name, String desc, int duration) {
this.id = id;
this.name = name;
this.description = desc;
this.duration = duration;
this.questions = new HashSet<Question>();
}
// #endregion
// #region overrides
public String toString() {
return "id: " + id + " / name: " + name + " / duration: " + duration;
}
// #endregion
// #region IInterview implementation
public void AddQuestions(Set<Question> questions, boolean force) throws DurationExcedeedException {
if (questions == null) {
return;
}
// if ! force : calculate the total duration
if (!force) {
int totalDuration = 0;
// first sum the existing question durations if any
for (Question var : this.questions) {
totalDuration += var.duration;
}
// then, add the new question durations
for (Question var : questions) {
totalDuration += var.duration;
}
// if the total exceeds the interview duration, raises an exception
if (totalDuration > this.duration)
throw new DurationExcedeedException("The total duration of the set of questions (" + totalDuration
+ ") exceeds the interview duration (" + this.duration + ")");
}
}
}