Question
Q4) Answer the following: [3 Marks] a) Write a declaration of a private field named library that can hold an ArrayList. The elements of the
Q4) Answer the following: [3 Marks]
a) Write a declaration of a private field named library that can hold an ArrayList. The elements of the ArrayList are of type Book.
b) Write a declaration of a private field called tracks for storing a collection of MusicTrack objects.
c) Write a method call to add the object held in the variable favoriteTrack to a collection called files.
d) Write a method call to remove the third object stored in a collection called dates.
e) Write out the header of a for-each loop to process an ArrayList called tracks. Dont worry about the loops body.
f) Write a while loop (for example, in a method called multiplesOfFive) that prints out all multiples of 5 between 10 and 95.
g) Write a declaration for an array variable people that could be used to refer to an array of Person objects.
Step 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