Can you write in your webpage and to tell student on the lecture (if there are any still) that students have to show me the program (at least that they can prove it that it works and they know the program - so they didnt copy it from somebody else).
Programmet SimpleSet från föreläsning 13 modifieras (här: SimpleSet.java).
Lägg till en iterator-klass:
iterator-metoden:public class SimpleSetIterator implements java.util.Iterator { private int currentPosition = 0; final Object[] content; public SimpleSetIterator(SimpleSet s) { content = s.content; } public boolean hasNext() { return currentPosition < MAX_MEMBERS && content[currentPosition] != null; } public Object next() { return content[currentPosition++]; } public void remove() { throw new UnsupportedOperationException(); } } // class SimpleSetIterator
Provkör:public java.util.Iterator iterator() { return new SimpleSetIterator(this); }
java.util.Iterator i = s.iterator(); int n = 0; while (i.hasNext()) { Point p = (Point)i.next(); assert p != null; ++n; } assert n == 3;
Ingen JavaBean-klass som man ärver från, utan Java-bönor följer vissa kodningsregler:
En egenskap, till exempel Color: