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.

MyList
-array:Object[] -size:int
+add(Object):boolean +getSize():int +iterator():Iterator

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, though. Integer 12 Double 42.5 String Hello Object null Boolean true

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!