CHAPTER 6 - Java Software Solutions, 4e Chapter 6...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Software Solutions, 4e Lewis/Loftus Chapter 6 Chapter 6 Exercise Solutions 6.1. Write a method called average that accepts two integer parameters and returns their average as a floating point value. public double average (int num1, int num2) { return (num1 + num2) / 2.0; } 6.2. Overload the average method of Exercise 4.9 such that if three integers are provided as parameters, the method returns the average of all three. public double average (int num1, int num2, int num3) { return (num1 + num2 + num3) / 3.0; } 6.3. Overload the average method of Exercise 4.9 to accept four integer parameters and return their average. public double average (int num1, int num2, int num3, int num4) { return (num1 + num2 + num3 + num4) / 4.0; } 6.4. Write a method called multiConcat that takes a String and an integer as parameters. Return a String that consists of the string parameter concatenated with itself count times, where count is the integer parameter. For example, if the parameter values are "hi" and 4 , the return value is "hihihihi" . Return the original string if the integer parameter is less than 2. public String multiConcat (String text, int repeats) { String result = text; if (repeats > 1) for (int count = 2; count <= repeats; count++) result += text; return result;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Software Solutions, 4e Lewis/Loftus Chapter 6 } 6.5. 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. For example, if the parameter is "test" , the return value is "testtest" public String multiConcat (String text) { String result = text + text; return result; } 6.6. Write a method called drawCircle that draws a circle based on the method's parameters: a Graphics object through which to draw the circle, two integer values representing the (x, y) coordinates of the center of the circle, another integer that represents the circle's radius, and a Color object that defines the circle's color. The method does not return anything. // assumes java.awt.* is imported
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 9

CHAPTER 6 - Java Software Solutions, 4e Chapter 6...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online