Practical Exercise 5 using BlueJ
These exercises are derived from Chaps 5 of the book. Download Projects
- Create a method containsStr which takes two String parameter which returns the position of the first matching character in the second string if the the first string is a substring of the second string and -1 otherwise.
Random Number Tester
- Create a new class called RandomTester which contains two methods
- printOneRandom which prints out a single random number, and
- printMultiRandom(int howMany) which has a parameter to specify how many numbers you want, and then prints out the appropriate number of random numbers.
- Write a method in your RandomTester called throwDice which returns a random number between 1 and 6
- Write a method called getResponse which randomly returns one of the strings "yes", "no" or "maybe".
- Extend your getResponse method so that it uses an ArrayList to store an arbitrary number of responses, and randomly returns one of them.