Question: Need to add an iterator, and the main functions. I believe add two more functions to get it working and please don't add another file.
Need to add an iterator, and the main functions. I believe add two more functions to get it working and please don't add another file. Please show code and what you add in bold and show output please.
// GoFIterator.java abstract class GoFIterator { abstract void first(); abstract void next(); abstract boolean isDone(); abstract int currentItem(); }
// IntegerBuffer.java public class IntegerBuffer { int data[]; int dataLength = 0; public IntegerBuffer(int capacity) { data = new int[capacity]; } public boolean add(int value) { if (dataLength < data.length) { data[dataLength] = value; ++dataLength; return true; } else return false; } public int add(int values[]) { int count = 0; for (int i = 0; i < values.length; ++i) if (add(values[i])) ++count; return count; } public static void main(String args[]) { int values[] = {23, 12, -6, 14, 0, 37, -26, 5, 11, -4, 16, 12, 8, -3, 6, -2}; IntegerBuffer ibuf = new IntegerBuffer(32);; ibuf.add(values); ibuf.add(values); System.out.println("Java"); /* // this section tests the iterator int column = 0; GoFIterator iter = ibuf.createIterator(); for (iter.first(); !iter.isDone(); iter.next()) { if (column >= 10) { System.out.println(); column = 1; } else ++column; System.out.format("%5d", iter.currentItem()); } System.out.println(); // end if iterator test */ } }
Output Java 23 12 -6 14 0 37 -26 5 11 -4 16 12 8 -3 6 -2 23 12 -6 14 0 37 -26 5 11 -4 16 12 8 -3 6 -2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
