Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 4.4 Write a declaration of a private field named library that can hold an ArrayList. The elements of the ArrayList are of type
Exercise 4.4 Write a declaration of a private field named library that can hold an ArrayList. The elements of the ArrayList are of type Book. Exercise 4.7 Write assignments to the library, cs101, and track variables (which you defined in the previous three exercises) to create the appropriate ArrayList objects. Write them once using diamond notation and once without diamond notation, specifying the full type. Exercise 4.8 If a collection stores 10 objects, what value would be returned from a call to its size method? Exercise 4.11 Write a method call to add the object held in the variable favoriteTrack to a collection called files. Exercise 4.12 Write a method call to remove the third object stored in a collection called dates. Exercise 4.13 Suppose that an object is stored at index 6 in a collection. What will be its index after the objects at index 0 and index 9 are removed? Exercise 4.14 Add a method called checkIndex to the MusicOrganizer class. It takes a single integer parameter and checks whether it is a valid index for the current state of the collection. To be valid, the parameter must lie in the range O to size()-1. If the parameter is not valid, then it should print an error message saying what the valid range is. If the index is valid, then it prints nothing. Test your method on the object bench with both valid and invalid parameters. Does your method still work when you check an index if the collection is empty? Exercise 4.30 Write a while loop (for example, in a method called multiplesOfFive) that prints out all multiples of 5 between 10 and 95. Exercise 4.47 The makeABid method includes the following two statements: Bid bid = new Bid(bidder, value); boolean successful = selected Lot.bidFor (bid); The bid variable is only used here as a placeholder for the newly created Bid object before it is passed immediately to the lot's bidFor method. Rewrite these statements to eliminate the bid variable by using an anonymous object as seen in the enterLot method.
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