Starting from:
$30

$24

Homework 5 Solution

Instructions




Please read the instructions carefully before submitting your work.




Note: There are 2 questions in this homework for a total of 50 points.










Note: Solve all problems and upload your answers to Moodle. Whenever you write solutions on paper, you need to scan all documents and upload the les to Moodle.










Note: user stands for your login ID on Polaris (polaris.clarkson.edu). This should be the exact same as your CU ID.










Note: Make sure any code you write works on Polaris before uploading your les. You will likely lose many points if your code doesn’t compile.










Note: Do not upload any executable or intermediate les as answers to problems, unless specif-ically asked to do so.













































































































Page 2 of 4
HW5 (EE 363) [ ]







[20 points] Write a class UtilMethodGenerics that contains a single standalone (i.e. static) function called exchange that has the following properties:



this function can be used to interchange the values of two user-speci ed locations of an array of any reference type




it should take three arguments in this order (from left to right): the array, the index of the rst location, and the index of the second location




it doesn’t return any value




Use the client in TestExchange to test the behavior of your method; see sample1.txt for the output of executing TestExchange with a correct implementation of exchange.




Now write another client, TestExchange2, that creates an array of type java.lang.Float of length at least 8 and uses exchange to swap the elements at the third and the last locations of this array.




In p1README.txt, explain how to run your program on Polaris.







Deliverable: Upload UtilMethodGenerics.java, TestExchange2.java, and p1README.txt to Moodle.






















































































































Page 3 of 4
HW5 (EE 363) [ ]







[30 points] Add iterator functionality to the IntSet type provided.



Make sure it works with drv1.java. The output of this driver with a correct iterator implementation is shown below:







[921, -100, 11, 0] {size: 4} (rep invariant check: true)




[IntSet.remove: nothing to remove as 3 is not in the set.]




[IntSet.remove: nothing to remove as 77 is not in the set.]




[921, -100, 11, 0, 100] {size: 5} (rep invariant check: true)







Testing IntSet’s iterator:




921 -100 11 0 100




Testing foreach loop with IntSets:




921 -100 11 0 100







Next, write your own driver in file2.java that creates an IntSet with 12 elements, and then prints them using traditional iterator traversal as well as using the foreach loop.




In p2README.txt, explain how to run your program on Polaris. Package (your) IntSet.java, file2.java, and p2README.txt along with all other les needed to run your code in a JAR le called userHW5p2.jar. (Note: user is your CU ID.)







Deliverable: Upload userHW5p2.jar to Moodle.

































































































End

More products