Lab: Practice with Java Collections Framework
Objective
In this lab you will experiment with the Java Collections Framework
(JCF) by implementing the static methods giveRaise and incrementAll
both with the OSU CSE collection components and also with the JFC
components and comparing and testing the two solutions.
Setup
To get started, import the project for this lab, JCFExplorations, from
the JCFExplorations.zip file available at this
link. If you don't remember how to do this, see
the Setup
instructions
in an earlier lab.
Method
- First carefully look through the file
JCFExplorations.java. It contains the skeletons for two versions each of two static methods,giveRaiseandincrementAll. The two versions of each method only differ in the type of one of the parameters. We used types fully qualified with the package name to make the distinction clear. - In
JCFExplorations.java, complete the bodies of the two versions of thegiveRaisestatic method by pasting the code you wrote for the homework. - Open the file
JCFExplorationsTest.javain thetestfolder and review the 2 sample test cases provided forgiveRaiseto see how they are set up and how you can test your implementations ofgiveRaise. Add appropriate test cases for both implementations ofgiveRaiseand run the JUnit test fixture until you are confident both that your implementations are correct and that your JUnit test fixture adequately tests your implementations. - In
JCFExplorations.java, complete the bodies of the two versions of theincrementAllstatic method. - In
JCFExplorationsTest.java, review the 4 sample test cases provided forincrementAllto see how they are set up and how you can test your implementations ofincrementAll. Add appropriate test cases for both implementations ofincrementAlland run the JUnit test fixture until you are confident both that your implementations are correct and that your JUnit test fixture adequately tests your implementations.
Additional Activities
- Can you think of any other ways you could correctly implement each
version of
giveRaiseandincrementAll? In particular, are other ways to iterate overMapandSetwith either the OSU CSE collection components or with the JCF components viable alternatives to the ones you chose? If you have not experimented with other approaches you should do so to get a better understanding of what can and cannot be done while iterating over collections.