Created
December 19, 2011 00:48
-
-
Save kbredemeier/1494970 to your computer and use it in GitHub Desktop.
se1 uebung 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity extends ActivityComponent { | |
private int time; | |
public Activity(int t) { | |
this.time = t; | |
} | |
public int count() { | |
return time; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ActivityComponent { | |
public void add(ActivityComponent c) { | |
throw new UnsupportedOperationException(); | |
} | |
public void remove(ActivityComponent c) { | |
throw new UnsupportedOperationException(); | |
} | |
public int count() { | |
throw new UnsupportedOperationException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActivityComponentTest { | |
public static void main(String[] args) { | |
ActivityComponent ac = new Process(); | |
ActivityComponent p1 = new Process(); | |
ActivityComponent a1 = new Activity(6); | |
ActivityComponent a2 = new Activity(5); | |
ActivityComponent a3 = new Activity(4); | |
ac.add(a1); | |
ac.add(p1); | |
p1.add(a2); | |
p1.add(a3); | |
System.out.println(ac.count()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Iterator; | |
public class Process extends ActivityComponent { | |
ArrayList components = new ArrayList(); | |
@Override | |
public void add(ActivityComponent c) { | |
components.add(c); | |
} | |
@Override | |
public void remove(ActivityComponent c) { | |
components.remove(c); | |
} | |
@Override | |
public int count() { | |
int time = 0; | |
Iterator i = components.iterator(); | |
while(i.hasNext()) { | |
ActivityComponent ac = (ActivityComponent) i.next(); | |
time = time + ac.count(); | |
} | |
return time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment