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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
class AssociationList<Key, Value> {
private class Node {
private Key key;
private Value value;
private Node next;
private Node(Key k, Value v, Node n) {
key=k; value=v; next=n;
}
}
public AssociationList() {
Node head = new Node("HEAD", "HEAD", null);
}
public void delete(Key key) {
}
public Value get(Key key) {
}
private boolean isEqual(Key leftKey, Key rightKey) {
if (leftKey == null || rightKey == null) {
return leftKey == rightKey;
} else {
return leftkey.equals(rightKey);
}
}
public boolean isIn(Key key) {
}
public void put(Key key, Value value) {
}
}
//
// Tests for CSci 1913 Lab 10
// James Moen
// 08 Apr 19
//
// The TRY-CATCH statements catch exceptions thrown by ASSOCIATION LIST's
// methods, so that the program can continue to run even if a method fails.
//
// Each test has a comment that shows what it should print and how many points
// it is worth, for a total of 40 points.
// HOGWARTS. The Hogwarts dating service.
class Hogwarts {
// MAIN. Make an instance of ASSOCIATION LIST and test it.
public static void main(String[] args) {
AssociationList<String, String> list = new AssociationList<String, String>();
System.out.println(list.isIn(null)); // false 2 points.
try {
System.out.println(list.get(null));
} catch (IllegalArgumentException ignore) {
System.out.println("No null"); // No null 2 points.
}
list.put(null, "Wormtail");
list.put("Ron", "Lavender");
list.put("Voldemort", null);
list.put("Dean", "Ginny");
System.out.println(list.isIn("Dean")); // true 2 points.
System.out.println(list.isIn("Ginny")); // false 2 points.
System.out.println(list.isIn("Ron")); // true 2 points.
System.out.println(list.isIn("Voldemort")); // true 2 points.
System.out.println(list.isIn(null)); // true 2 points.
System.out.println(list.isIn("Joanne")); // false 2 points.
System.out.println(list.get("Ron")); // Lavender 2 points.
System.out.println(list.get("Dean")); // Ginny 2 points.
System.out.println(list.get("Voldemort")); // null 2 points.
System.out.println(list.get(null)); // Wormtail 2 points.
try {
System.out.println(list.get("Joanne"));
} catch (IllegalArgumentException ignore) {
System.out.println("No Joanne"); // No Joanne 2 points.
}
list.delete(null);
System.out.println(list.isIn(null)); // false 2 points.
list.put(null, null);
list.put("Harry", "Ginny");
list.put("Ron", "Hermione");
System.out.println(list.isIn(null)); // true 2 points.
System.out.println(list.get(null)); // null 2 points.
System.out.println(list.get("Harry")); // Ginny 2 points.
System.out.println(list.get("Dean")); // Ginny 2 points.
System.out.println(list.get("Ron")); // Hermione 2 points.
list.delete("Dean");
try {
System.out.println(list.get("Dean"));
} catch (IllegalArgumentException ignore) {
System.out.println("No Dean"); // No Dean 2 points.
}
}
}
|