Question: (Java) Write a MyList class that implements Iterable The constructor instantiates an array of 1000 Objects. The add(Object) method returns false if there is no
(Java) Write a MyList class that implements Iterable
The constructor instantiates an array of 1000 Objects.
The add(Object) method returns false if there is no room in the array, else adds the argument as the last element in the array, incrementing size.
Write a driver to instantiate a MyList, add a variety of different type Objects, such as 12, 42.5, "Hello", null, and true, and to then use an enhanced for loop (a foreach loop) to print out the word "String " if it is a String, "Double " if it is a Double, "Integer " if it is an Integer, "Boolean " if it is a Boolean, and "Object " if it is anything else, each followed by the Object. The output for the example Objects above would be as follows. Make up your own Objects. Integer 12 Double 42.5 String Hello Object null Boolean true
MyList -array:Object[] -size:int +add(Object):boolean +getSize():int +iterator():Iterator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
