Test Your Knowledge: Exercises

Exercise 8-1. Write a program with an overloaded method for tripling the value of the argument. You don’t need to create a separate class for this; just use static methods right in Tester. One version of the method should triple an int value, and the other version should triple a float value. Call both methods to demonstrate that they work.

Exercise 8-2. Create a Dog class, where the Dog objects have both a weight and a color, hidden from the client. Create a Dog object, then retrieve its color and display it to the user. Ask the user for a weight, and use that input to set the Dog’s weight.

Exercise 8-3. Write a program with just one method that takes an int value, supplied by the user, and returns both double and triple that value. You don’t need a separate class; just put the method in Tester. In Run( ), output the results to the console to make sure it worked.

Exercise 8-4. Modify the program from Exercise 8-3 so that you don’t need to initialize the variables that will hold the doubled and tripled values before calling the method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset