1

Overload the multiConcat method from Exercise 4.12 such that if the integer
parameter is not provided, the method returns the string concatenated with itself.
... 0 and 255 representing the contributions of red, green, and blue (its RGB value
). final int MAX = 256;. // assumes java.util.Random and java.awt.Color are
imported.

Part of the document


Chapter 4: Writing Classes
Solutions

|Multiple Choice |True/False |
|Solutions |Solutions |
|b |T |
|c |F |
|d |T |
|b |F |
|e |T |
|d |T |
|a |F |
|e |F |
|a |F |
|b |F |


Short Answer Solutions


1. Write a method header for a method named translate that takes an
integer parameter and returns a double.

double translate (int param)

2. Write a method header for a method named find that takes a String and
a double as parameters and returns an integer.

int find (String str, double num)



3. Write a method header for a method named printAnswer that takes three
doubles as parameters and doesn't return anything.

void printAnswer (double d1, double d2, double d3)



4. Write the body of the method for the following header. The method
should return a welcome message that includes the user's name and
visitor number. For example, if the parameters were "Joe" and 5, the
returned string would be "Welcome Joe! You are visitor #5."

String welcomeMessage (String name, int visitorNum)

{

return "Welcome " + name + "! You are visitor #" + visitorNum;

}

5. Write a method called powersOfTwo that prints the first 10 powers of 2
(starting with 2). The method takes no parameters and doesn't return
anything.



public void powersOfTwo()
{

int base = 2;
for (int power = 1; power