Question
Need to add an iterator, and the main functions. I believe that you need to add five functions and nested class definition. Please fulfill out
Need to add an iterator, and the main functions. I believe that you need to add five functions and nested class definition. Please fulfill out the code without changing anything that is posted below and explain why you picked those functions and how the nested class definition with the iterator work. Please show output that you have received.
// 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started