Objects First With Java - Solutions

Jun 16, 2006 ... Exercise 5.9. add the line: input = input.toLowerCase(); to the start()-method of
SupportSystem. Exercise 5.10. boolean. Exercise 5.11. if(input.equals("bye")) {
finished = true; }. Exercise 5.12. Package: java.util. It generates random numbers.
An instance is created by using one of the two constructors:

Part of the document



|Exercise 5.2 |
|The documentation contains the following sections: |
|Overall description of the class: its purpose and how to use it |
|A brief summary of the fields |
|A brief summary of the constructors |
|A brief summary of the methods |
|A detailed description of the fields |
|A detailed description of the constructors |
|A detailed description of the methods |
|Exercise 5.4 |
|Yes: public boolean endsWith(String suffix) |
|Exercise 5.5 |
|Yes: public int length() |
|Exercise 5.7 |
|Signature: public String trim() |
|Example: String trimmedText = text.trim(); |
|Control characters are treated as whitespace: "...it trims all |
|ASCII control characters as well" |
|Exercise 5.8 |
|add the line: input = input.trim(); |
|to the start()-method of SupportSystem |
|Exercise 5.9 |
|add the line: input = input.toLowerCase(); |
|to the start()-method of SupportSystem |
|Exercise 5.10 |
|boolean |
|Exercise 5.11 |
|if(input.equals("bye")) { |
|finished = true; |
|} |
|Exercise 5.12 |
|Package: java.util |
|It generates random numbers |
|An instance is created by using one of the two constructors: |
|Random random = Random(); |
|Random random = Random(long seed); |
|To generate a random integer: |
|random.nextInt(); |
|Exercise 5.13 |
|Random random = Random(); |
|random.nextInt(); |
|Exercise 5.14 |
|import java.util.Random; |
| |
| |
|public class RandomTester |
|{ |
|private Random random; // the random number generator |
| |
|public RandomTester() |
|{ |
|random = new Random(); |
|} |
| |
|public void printOneRandom() |
|{ |
|System.out.println(random.nextInt()); |
|} |
| |
|public void printMultiRandom(int howMany) |
|{ |
|for(int i=0; i