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():IteratorStep 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