forked from dr-cs/intro-oop-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDobermanGangSubverter.java
More file actions
39 lines (34 loc) · 1.31 KB
/
DobermanGangSubverter.java
File metadata and controls
39 lines (34 loc) · 1.31 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
public class DobermanGangSubverter {
public static void main(String[] args) {
DobermanGang dg =
new DobermanGang("Chloe");
// http://en.wikipedia.org/wiki/The_Doberman_Gang
dg.add(new Doberman("Dillinger"));
dg.add(new Doberman("Bonnie"));
dg.add(new Doberman("Clyde"));
dg.add(new Doberman("Pretty Boy Floyd"));
dg.add(new Doberman("Baby Face Nelson"));
dg.add(new Doberman("Ma Barker"));
System.out.println(dg);
// td is a reference to dg's private
// topDog instance variable
Doberman td = dg.getTopDog();
td.setName("Bailey");
System.out.println(dg);
// prettyBoy is a reference to dg's
// private gang[3] instance variable
Doberman prettyBoy = dg.get(3);
prettyBoy.setName("Pink Floyd");
System.out.println(dg);
// array variables also references,
// so can get an alias to whole array
Doberman[] theGang = dg.getGang();
// http://en.wikipedia.org/wiki/Teletubbies
theGang[0] = new Doberman("Tinky Winky");
theGang[1] = new Doberman("Dipsy");
theGang[2] = new Doberman("Laa Laa");
theGang[3] = new Doberman("Po");
theGang[4] = new Doberman("Noo Noo");
System.out.println(dg);
}
}