Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following interface: public interface KnapsackItem public int aetwelahtO public int aetValue) Write a GoldRing class that makes use of the interface. Include a
Consider the following interface: public interface KnapsackItem public int aetwelahtO public int aetValue) Write a GoldRing class that makes use of the interface. Include a toStrinal method to report the name of the item (Gold Ring), its value, and its weight. Call the interface methods from the taStrina) method. (10 points) public int compare(Object o1, Object o2); Write a Comparator called CompareKnapsackItems. The constructor accepts a boolean to determine whether the individual Knapsackltems should be compared by value (true) or by weight (false) in ascending order in either case. Use proper generics wherever appropriate. (15 points) Write a KnapsackItems class that has-a List to store a collection of items that use the Knapsackltem interface. The constructor (5 points) takes an integer that specifies the max.weight (if maxweight is invalid, throw a KnapsackException). Assume a ListFactory exists to create the List for you. Use proper generics wherever appropriate. Complete the following four methods in the Knapsackltems class plus the constructor. Use the provided blank page. Assume KnapsackException exists as a RuntimeException. O. Provide thorough javadoc documentation for the addItem method (preconditions, postconditions, and throws) (10 points)
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