A certain application needs to store three types of object. Each type has a comm
ID: 3643383 • Letter: A
Question
A certain application needs to store three types of object. Each type has a common method, rating(), that returns a double between 0.0 and 1.0. Otherwise the different types of object have different characteristics and behavior. The application needs to store many objects of these three types so that they can easily be accessed in order of their ratings. Assume that the three types will be defined by three classes: TypeA, TypeB, TypeC. Which of the following is the best design for this application?A.) Store the objects in three ArrayLists: ArrayList<TypeA>, ArrayList<TypeB>, ArrayList<TypeC>, each maintained in order by rating when items are stored.
B.) Declare a class TypeCollection that has three unordered ArrayLists as instance variables: ArrayList<TypeA>, ArrayList<TypeB>, ArrayList<TypeC>.
C.) Declare a class TypeCollection that has three ArrayLists as instance variables: ArrayList<TypeA>, ArrayList<TypeB>, ArrayList<TypeC>, each maintained in order by rating when items are stored.
D.) Store the objects in a single ArrayList (of Object) ordered by rating.
E.) Declare an Interface Rateable that specifies one method, rating(), that returns a double. Define each of these classes TypeA, TypeB, TypeC to implement this interface. Store the objects in an ArrayList<Rateable> ordered by rating.
Explanation / Answer
E.) Declare an Interface Rateable that specifies one method, rating(), that returns a double. Define each of these classes TypeA, TypeB, TypeC to implement this interface. Store the objects in an ArrayList ordered by rating.Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.