Question: Now imagine that you're writing client code for your revised ValuePair class - i.e., code in a different class that uses ValuePair objects. For each

 Now imagine that you're writing client code for your revised ValuePair class - i.e., code in a different class that uses ValuePair objects.

For each of the following tasks, write a single line of client code to accomplish the task:

Construct a ValuePair object for the pair (7, 15.5), and assign it to a properly declared variable named vp1.

A. Change the integer value in the ValuePair object that you created in part (a), giving it a value of 25. You should not create a new object; you should change the internals of the existing object.

Important: As a result of your changes from part 1, clients no longer have direct access to the fields B. in a ValuePair object. As a result, you will need to make a method call to change the appropriate field.

C. Get the real-number value in the ValuePair object that you created in part (a), and assign it to a properly declared variable named b1. Here again, you will need to make an appropriate method call.

D. Now imagine that you are given a second ValuePair object that has been created by someone else and that has been assigned to the variable vp2. Change the integer value in vp2, giving it a value that is 2 more than its current value.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here are the client code lines to accomplish each task A Construct a ValuePair ob... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!