1)An invoice contains a collection of purchased items. Should that collection be
ID: 3701621 • Letter: 1
Question
1)An invoice contains a collection of purchased items. Should that collection be implemented as a list or set? Explain your answer.
2)Consider a program that manages an appointment calendar. Should it place the appointments into a list, stack, queue, or priority queue? Explain your answer.
3)One way of implementing a calendar is as a map from date objects to event objects. However, that only works if there is a single event for a given date. How can you use another collection type to allow for multiple events on a given date?
4)Look up the descriptions of the methods addAll, removeAll, retainAll, and containsAll in the Collection interface. Describe how these methods can be used to implement common operations on sets (union, intersection, difference, subset).
5)Explain what the following code prints. Draw a picture of the linked list after each step.
LinkedList<String> staff = new LinkedList<>();
staff.addFirst("Harry");
staff.addFirst("Diana");
staff.addFirst("Tom");
System.out.println(staff.removeFirst());
System.out.println(staff.removeFirst());
System.out.println(staff.removeFirst());
Explanation / Answer
Hi, I have answered first two questions.
Please repost others in separate post.
Please let me know in case of any issue in answered part.
1)An invoice contains a collection of purchased items. Should that collection be implemented as a list or set? Explain your answer.
Ans: Set. Since list of items should be unique, so we should main in SET so that there
will be no duplicay.
2)Consider a program that manages an appointment calendar. Should it place the appointments into a list, stack, queue, or priority queue? Explain your answer.
Ans: Queue. because whoever takes appointmnt early, they will get chance early.
So, this is first-in first-out case
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.