Aeromodelling
We just finished gluing all the parts after spending 4 finger-breaking hours sandpapering the balsa wood to give it the required aero Dynamics.
Snaps here
public class TestingPassByValue {
public static void main(String[] args) {
String object1 = "Hello";
display(object1);
changeAndDisplay(object1);
display(object1);
}
private static void changeAndDisplay(String object1) {
object1 = "Changed Hello";
display(object1);
}
private static void display(String object1) {
System.out.println(object1);
}
}
// job: Understands how myContainer and myContainerIterator work and verifies it
public class IteratorTest extends TestCase {
private MyContainer myContainer;
protected void setUp() throws Exception {
myContainer = new MyContainer();
myContainer.add("Hello");
}
public void testCreateIteratorReturnsAnIterator() {
assertNotNull(myContainer.iterator());
}
public void testAddingToMyContainer() {
assertEquals("Hello", myContainer.get(0));
}
public void testIteratorWorksWithMultipleAdditions() {
Iterator iterator = myContainer.iterator();
assertEquals("Hello", iterator.next());
myContainer.add("Yo");
assertEquals("Yo", iterator.next());
}
}
My Collection class
// Job: Understands a collection
public class MyContainer {
private List storage = new ArrayList();
public void add(Object s) {
storage.add(s);
}
public Object get(int i) {
return storage.get(i);
}
Iterator iterator() {
return new MyContainerIterator(storage);
}
}
My Iterator
//job: Understands how to traverse over a MyContainer Collection
public class MyContainerIterator implements Iterator {
private List storage;
int index;
public MyContainerIterator(List storage) {
this.storage = storage;
}
public boolean hasNext() {
return index < storage.size();
}
public Object next() {
return storage.get(index++);
}
public void remove() {
}
}
// Job: Understands a collection
public class MyContainer {
private List storage = new ArrayList();
public void add(Object s) {
storage.add(s);
}
public Object get(int i) {
return storage.get(i);
}
Iterator iterator() {
return new MyContainerIterator(storage);
}
//job: Understands how to traverse over a MyContainer Collection
private class MyContainerIterator implements Iterator {
private List storage;
int index;
public MyContainerIterator(List storage) {
this.storage = storage;
}
public boolean hasNext() {
return index < storage.size();
}
public Object next() {
return storage.get(index++);
}
public void remove() {
}
}
}