1 / 17

Review Question 1

Review Question 1. Every instance of the Fraction class has a long numerator. We do not call the relation between Fraction and the long type an aggregation. Why not?. What is aggregation?.

Download Presentation

Review Question 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review Question 1 • Every instance of the Fraction class has a long numerator. • We do not call the relation between Fraction and the long type an aggregation. • Why not?

  2. What is aggregation? • If one of the attributes of a class C is an object reference of type T (other than String), then C is an aggregate and T is the aggregated part. Aggregation = has-a

  3. Review Question 2 • Which class is the aggregate? • Is it a collection? • What can be said about the number/type of attributes in the aggregate? • Is this a composition? A B 3

  4. What is composition? • An aggregation where the aggregate and the parts have a shared lifetime • Constructed together • Destroyed (orphaned) together

  5. Review Question 4 • The accessor to a part in a composition should not return a reference to the actual part instance but to a copy of it • Explain why not

  6. Review Question 6 • Explain the meaning of “aliasing an object”

  7. Review Question 7 • Given an instance of an aggregate, suppose that someone copied the block it occupies in memory, bit by bit to a new block • Argue that the new block would be a shallow copy of the aggregate, not a deep one

  8. Review Question 8 • Given two instances of a class whose attributes are all public, how can you determine whether one instance is a shallow copy of the other?

  9. Exercise 7 • Write a program that determines whether or not the type.lib.Fresh aggregate is a composition with respect to the Date class

  10. Review Question 20 • If a collection is statically allocated, then what should be passed to its constructor? static = compile-time dynamic = run-time

  11. Review Question 21 • Can you add an element to a collection even if it is already in it? Set collections - No List collections - Yes

  12. Review Question 22 • What happens if you attempt to add an element to a full, statically allocated collection?

  13. Exercise 9 • Write a program that generates a random portfolio of investments using the getRandom method of the Portfolio class • Use indexed access to traverse the portfolio (visit all its elements), and output its total market value

  14. Exercise 10 • Write a program that generates a random portfolio of investments using the getRandom method of the Portfolio class • Use iterator-based access to traverse the portfolio (visit all its elements), and determine which investment has the highest market value

  15. Review Question 28 • A linear search takes 5 sec in the worst case on a collection of 5,000 elements • How long will it take in the worst case on a collection of 20,000 elements? Linear search = complexity O(N) T(N) ≈  N

  16. Review Question 29 • Repeat question 28 but for a search algorithm with O(N1/2) complexity

  17. Review Question 30 • Repeat question 29 but for a search algorithm with O(lgN) complexity • lg = base 2 logarithm

More Related