Question 2 Listed next is a code skeleton for an interface called Enumeration and a class...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 } 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 }
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these computer network questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Question 4: What is meant by statistical versus nonstatistical and probabilistic versus nonprobabilistic sample selection?
-
A meteoroid is traveling east through the atmosphere at 18.3 km/s while descending at a rate of 11.5 km/s. What is its speed, in km/s?
-
Refer to the facts in Problem I:10-47 for John and Ellen Brite. The following information is also available for them: The business uses the accrual method and did not make any payments that would...
-
Rank the magnet pairs in Figure P27.15 in order of the magnitude of torque on magnet 2 , smallest torque first. Assume all the magnets are equal in strength and the spacing between magnets is...
-
Watson Technical Institute (WTI), a school owned by Tom Watson, provides training to individuals who pay tuition directly to the school. WTI also offers training to groups in off-site locations. Its...
-
6. 7. 8. If one of the diameters of the circle x + y-2x-6y+6=0 is a chord of another circle 'C', whose centre is at (2, 1), then its radius is Let Bi (i = 1, 2, 3) be three independent events in a...
-
During the 2023 FBT year, Karma Security (Karma) provided the following fringe benefits to Ben, a general manager: College fees expense payment benefit $2,000 taxable value Loan fringe benefit $2,000...
-
If you were conducting an actuarial valuation for an Australian defined benefit superannuation fund, what assumption for salary (wage) inflation would you use? In particular, consider a fund whose...
-
1- Pick a company/industry (this can be a firm or industry that you currently work in) and explain how you would go about estimating the demand for your product or service. 2- Also form a regression...
-
What are the similarities and differences between Theodor Adorno and colleagues (1950) and Billing 1995 in their concepts, theoretical approaches, assumptions and methods on the formation of a...
-
How organizations use testing in their diversity strategy. Use this to guide you: "Organizations use testing as a device for ensuring they hire the right person, as a tool for helping employees...
-
Show all the workings and explain the position of the directional vector for your company in a specific quadrant and recommend which strategy JP Morgan should pursue, given their position on the...
-
3. (a) If A be an n xn invertible matrix. Prove that the transpose of A is also invertible.
-
a) Calculate the goodwill that was paid by Major Ltd on the acquisition of Minor Ltd. [10 marks] b) Prepare the consolidated statement of financial position for Major Ltd at 31 July 20X8. [30 marks]...
-
John Fuji (age 37) moved from California to Washington in December 2011. He lives at 468 Cameo Street, Yakima, WA 98901. John's Social Security number is 571-78-5974 and he is single. His earnings...
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
During 2012, William purchases the following capital assets for use in his catering business: New passenger automobile (September 30)........................$21,500 Baking equipment (June 30)...
-
The following accounts and amounts (balances are normal balances) were taken from the records of Prider Manufacturers Ltd at 30 June 2019. Required (a) Prepare a cost of goods manufactured statement...
-
The following data were taken from the records of Manik Manufacturing Ltd for the year ended 30 June 2019. Required (a) Prepare the cost of goods manufactured schedule for the year ended 30 June...
-
The following demonstration problem illustrates the use of the general journal, the four special journals introduced here, and the general ledger with two subsidiary ledgers. Sidney Carton began...
Study smarter with the SolutionInn App