Practical Exercise 5 using BlueJ

These exercises are derived from Chaps 5 of the book. Download Projects


  1. 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

  2. Create a new class called RandomTester which contains two methods
    1. printOneRandom which prints out a single random number, and
    2. printMultiRandom(int howMany) which has a parameter to specify how many numbers you want, and then prints out the appropriate number of random numbers.
  3. Write a method in your RandomTester called throwDice which returns a random number between 1 and 6
  4. Write a method called getResponse which randomly returns one of the strings "yes", "no" or "maybe".
  5. Extend your getResponse method so that it uses an ArrayList to store an arbitrary number of responses, and randomly returns one of them.