Projects When you create or modify classes in the following projects, be sure to test your changes by running an appropr

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Projects When you create or modify classes in the following projects, be sure to test your changes by running an appropr

Post by answerhappygod »

Projects When You Create Or Modify Classes In The Following Projects Be Sure To Test Your Changes By Running An Appropr 1
Projects When You Create Or Modify Classes In The Following Projects Be Sure To Test Your Changes By Running An Appropr 1 (635.83 KiB) Viewed 32 times
Projects When You Create Or Modify Classes In The Following Projects Be Sure To Test Your Changes By Running An Appropr 2
Projects When You Create Or Modify Classes In The Following Projects Be Sure To Test Your Changes By Running An Appropr 2 (352.98 KiB) Viewed 32 times
Projects When you create or modify classes in the following projects, be sure to test your changes by running an appropriate tester program. 1. Add the eg method to the ArraySortedBag class discussed in this chapter. This method should run in no worse than linear time. 2. Modify the LinkedBag class discussed in Chapter 5, so that it becomes a subclass of AbstractBag. Be sure to retain in LinkedBag only those methods that cannot be moved to AbstractBag. Complete the AbstractCollection dass discussed in this chapter. Then revise the AbstractBag class so that it behaves as a subclass of AbstractCollection. 1. As you learned in Projects 6 and 7 of Chapter 5, a set behaves just like a bag, except that a set cannot contain duplicate items. Some possible implementations are ArraySet and LinkedSet. Draw a class diagram that shows where you would place these new classes in the collection framework shown in Figure 6-4. 5. Complete the classes for ArraySet and LinkedSet, so they use inheritance to maximum advantage.
6. A sorted set behaves just like a set, but allows the user to visit its items in ascend- ing order with a for loop, and supports a logarithmic search for an item. Draw a class diagram that shows where you would place a new class for sorted sets in the collection framework shown in Figure 6-4. 7. Complete the new class for sorted sets. 8. Someone notices that the remove operation performs two searches of a bag: one during the test of the method's precondition (using the in operator) and the other to locate the position of the target item to actually remove it. One way to eliminate the redundant search is to track the position of the target item in an instance variable. In the case of an array-based bag, this position would be -1 at startup and whenever a target item is not found. If the in operator finds a target item, the position variable is set to that item's index in the array; otherwise, it is reset to -1. After the remove method checks its precondition, no search loop is necessary; the method can just close the hole in the array lising the position vari- able. Modify the ArrayBag class to support this capability. Note that you will now have to add a contains method to ArrayBag that performs this customized search. 9. The modified remove method of Project 8 no longer works correctly for a sorted bag. The reason for this is that the contains method in ArrayšortedBag does not update the new position variable in ArrayBag. Nlodify the method ArraySortedBay. contains so that the remove tellivu wonksuurteouly for sorted bags. 10. The remove method in the LinkedBag class has the redundant search described in Project 8. Modify this class so that thus redundancy no longer exists.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply