Chap06 EX Solutions

Chap06 EX Solutions - Java Software Solutions 6th Edition...

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

View Full Document Right Arrow Icon
Java Software Solutions, 6 th Edition Exercise Solutions, Ch. 6 Chapter 6 Exercise Solutions EX 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; } EX 6.2. Overload the average method of Exercise 6.1 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; } EX 6.3. Overload the average method of Exercise 6.1 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; } EX 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 count) { String result = text; if (repeats > 1) for (int i=2; i <= count; i++) result += text; return result; } EX 6.5. Overload the multiConcat method from Exercise 6.4 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) { return text + text;
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, 6 th Edition Exercise Solutions, Ch. 6 } EX 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
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 07/26/2011 for the course COP 2551 taught by Professor Roggio,r during the Summer '08 term at UNF.

Page1 / 6

Chap06 EX Solutions - Java Software Solutions 6th Edition...

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