Question: Write a java program it will have the following private data members: Integer intResult; Boolean booleanResult; String stringResult; This class will be called DoWorkResults class.

Write a java program it will have the following private data members:

Integer intResult; Boolean booleanResult; String stringResult;

This class will be called DoWorkResults class. It must be able to hold any one of these three types: integer, string, boolean.

It will have public methods to get and set each of the data members. It will have a public String toString() method that returns a String with the result. (There is only one result in each class. Do not put 'null' into the returned string. You will need to check each data member to see if it a null reference, and only return a String created from the non-null data member.)

Answer the Questions

  • The classes now each have doWork() methods with identical signatures and identical return types. Does this help use or organize the classes at all? In other words, is there any advantage in making the code so that the doWork() method is identical in all 3 methods?
  • What is the difference between the Integer class and the int primitive? Likewise, what is the difference between the Boolean class and the boolean primitive data type?
  • Imagine that you implemented code to meet the challenge. What if you wrote another class that had a doWrok() method that returned a DoWorkResults object. Would you need to modify the code in your loop? Is this a good thing?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!