Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 Listed next is a code skeleton for an interface called Enumeration and a class called NameCollection. Enumeration provides an interface to sequentially


imageimage

Question 2 Listed next is a code skeleton for an interface called Enumeration and a class called NameCollection. Enumeration provides an interface to sequentially iterate through some type of collection. In this case, the collection will be the class Name Collection that simply stores a collection of names using an array of strings. public interface Enumeration { } // Returns true if another element in the collection exists public boolean hasNext (); // Returns the next element in the collection as an Object public Object getNext (); /** * NameCollection implements a collection of names using a simple array. public class NameCollection { String[] names; The list of names is initialized from outside * and passed in as an array of strings */ public NameCollection (String[] names) { this.names - names; ).. + getEnumeration should return an instance of a class that implements the Enumeration interface where hasNext () and getNext () * correspond to data stored within the names array. / public Enumeration getEnumeration () { } // Complete code here using an inner class Complete the method getEnumeration () so that it returns an anonymous inner class that corresponds to the Enumeration interface for the names array in NamesCollection. Then write a main method that creates a NamesCollection object with a sample array of strings, retrieves the Enumeration for this class via getEnumeration (), and then iterates through the enumeration outputting each name using the getNext () method. skeleton code: public interface Enumeration { // Returns true if another element in the collection exists public boolean hasNext(): // Returns the next element in the collection as an Object public Object getNext(): } * NameCollection implements a collection of names using a simple array. */ public class NameCollection { String[] names: * The list of names is initialized from outside and passed in as an array of * strings */ } public NameCollection(String[] names) { this.names = names; } getEnumeration should return an instance of a class that implements the * Enumeration interface where hasNext() and getNext() correspond to data stored *within the names array. * */ public Enumeration getEnumeration() { // Complete code here using an inner class }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Computer Network questions

Question

How do computers aid in solving LP problems today?

Answered: 1 week ago