Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7.1. a. Implement a generic class Pair that stores pairs of (key, value) pairs. Usage example: Pair p = new Pair (1, one); System.out.println(The string

7.1.

a. Implement a generic class Pair that stores pairs of (key, value) pairs.

Usage example: Pair p = new Pair<>(1, "one"); System.out.println("The string value of " + p.k() + " is " + p.v());

A pair object has a constructor

public Pair(K k, V v) {...}

has accessors:

public K k() {...} public V v() {...}

and overrides these methods inherited from class Object:

public boolean equals(Object obj) {...} public int hashCode() {...} public String toString() {...} public Object clone() {...}

Your class must be immutable, serializable, and cloneable. It is OK to return a shallow clone. Follow the guidelines from the textbook when implementing the above functions.

b. Write a PairTest class with method main() where you test: - equality with equals() - cloning : make a clone and compare with the original - serialization. Serialize to an ObjectStream backed by a file and then load the object back to memory and compare it to the original with equals(). - hashCode(). Must be compatible with equals (i.e. equal hashCode() for equal objects, and different values (with high probability) for different key or/and value objects

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago