-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssessment.java
More file actions
60 lines (56 loc) · 1.89 KB
/
Copy pathAssessment.java
File metadata and controls
60 lines (56 loc) · 1.89 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
import java.util.HashMap;
public class Assessment {
private HashMap<String,Integer> pairs;
public Assessment(){
pairs= new HashMap<>();
}
public HashMap<String, Integer> getPairs() {
return pairs;
}
public void addAssessment(String var, int value){
//Pre: var is not empty.
//Post: If var already has a value, it is replaced. If not, the new assessment is added.
pairs.put(var,value);
}
public void removeAssessment(String var){
//Pre:
//Post: Assessment var is removed if it exists
pairs.remove(var);
}
public int getAssessment(String var){
//Pre:
//Post: It returns value from var given, if var doesn´t exists, it returns null.
return pairs.get(var);
}
public boolean hasValue(String var){
//Pre:
//Post: Returns true if there is a var in the assessment table; false in contrary case.
return pairs.containsKey(var);
}
public boolean areCompatible(Assessment a){
//Pre: Assessment given is not null.
//Post: It returns true if equals vars in both assessment have the same value; false in contrary case.
for(String var:a.pairs.keySet()){
if (pairs.get(var)!=null){
if(pairs.get(var)!=a.getAssessment(var)) return false;
}
}
return true;
}
public Assessment union(Assessment a){
//Pre: Assessment given must be compatible.
//Post: It returns the union of the both assessment (this and given).
Assessment union = new Assessment();
for(String var:a.pairs.keySet()){
union.pairs.put(var,pairs.get(var));
}
for(String var2:this.pairs.keySet()){
union.pairs.put(var2,pairs.get(var2));
}
return union;
}
@Override
public String toString() {
return super.toString();
}
}