Quick Index
Objectives
Steps
Problem Statement
Hints
Solution
Test Code
Objectives
Java generics
Pair concepts
Java packages
Writing Test Code
Steps
Take a shot at writing the program after viewing the problem statement
When desired, look at
the hints
When desired, look at
the solution
Problem Statement
Concept
A pair is a general purpose class that models a "pair" (i.e. a set of two).
One particular case is when you need to return two objects from a method.
Pair is a simple modeling object type:
Pair first second
📋
The instance variables (ivars) are "first" and "second".
Coding requirements:
Write a class that uses generic type parameters "T" and "S" specified on the class that specifies the value types for ivars "first" and "second", respectively
Write a constructor that receives values to set all ivars
Write a
getter
for each ivar
Write a
setter
for each ivar
Hints
You only need two ivars, one constructor, and four instance methods for the Pair class
Solution
Here is
code with explanations
Test Code
Testing Problem Statement
Also reference the
Association test write-up
as needed.
Write code to test the model. If you get stumped, look at test code solution.
Test Code Solution
First, try to write test code yourself. Then review and compare the following for possible ideas.
Pair Smoke Test
Pair Test
Here is
support code
that is needed for the test code.
Note that this support code is just one example of a minimal testing framework. Feel free to build your own.
Object Oriented Programming
Pair
Top
Search
TOC