Java Software Solutions, 8e, Global Edition Exercise Solutions, Ch. 4
Chapter 4 Exercise Solutions
EX 4.1. For each of the following pairs, which represents a class and which represents an
object of that class?
a. Weekdays, Friday
b. Java, Language
c. Bird, Eagle
d. Bob, Employee
e. Student, Alice
EX 4.2. List some attributes and operations that might be defined for a class called
WindowPane that represents a window pane.
EX 4.3. List some attributes and operations that might be defined for a class called
Examination that represents a business meeting.
EX 4.4. List some attributes and operations that might be defined for a class called Course
that represents a college course (not a particular offering of a course, just the
course in general).
EX 4.5. Write a method called synonyms that prints at least two synonyms of a word when
invoked. The method should accept no parameters and return no value.
}
EX 4.6. Write a method that accepts two integers and returns the first integer raised to the
power of second integer.
}
EX 4.7. Write a method called random100 that returns a random integer in the range of 1 to 100
(inclusive).
}
EX 4.8. Write a method called randomInRange that accepts two integer parameters
representing a range. The method should return a random integer in the specified
range (inclusive). Assume that the first parameter is greater than the second.
public int randomInRange(int first, int second)
}
EX 4.9. Write a method called randomColor that creates and returns a Color object that
represents a random color. Recall that a Color object can be defined by three integer
values between 0 and 255 representing the contributions of red, green, and blue (its
RGB value).
final int MAX = 256; public Color randomColor(){
EX 4.10. Suppose you have a class called Movie. Write a constructor for the class that
initializes the title and director instance variables based on parameters passed
to the constructor.
}
EX 4.11. Suppose you have a class called Child with an instance data value called age.
Write a getter method and a setter method for age.
public int getAge()
}
EX 4.12. Draw a UML class diagram that shows the relationships among the classes used
in the Transactions program.
EX 4.13. Draw a UML class diagram that shows the relationships among the classes used
in the PushCounter program.
Java Software Solutions, 8h Edition Exercise Solutions, Ch. 4
EX 4.14. Draw a UML class diagram that shows the relationships among the classes used
in the Fahrenheit program.