Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

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

Students also viewed these Databases questions