Goal of this lab
Give you practice with for-loops and functions.
Start a new folder named lab07. Open the course web page in a browser, click on “Labs”, and download file Lab07.java into folder lab07. Open the file in DrJava. Class Lab07 contains two partially completed functions and two function with only return statements, so that they compile.
Overview of lab
You have to complete the functions in class Lab07. Each will contain a loop. Write one at a time, implementing the specification that we give you. Make sure each function is correct before proceeding to the next one. Do this by writing suitable calls in DrJava’s interactions pane. Use enough different test cases so that you really are sure that the function is correct. If the function uses a string value, make sure that it works on an empty string (one whose length is 0).
You may not finish all four functions during the lab. Near the end of the lab, show an instructor or consultant what you have done. Try to complete the lab during the next week and show what you have done to the instructor or consultant next week.
Below, we show you on paper the functions you will be writing.

Function 1.
Complete the following function (filling in the underlined things). Test your function to make sure it is right.
/** = “p is a prime.” i.e. is at least 2
       and is divisible by only 1 and itself */
public static isPrime(int p) {
if (p < 2)
return _____________;
if (p == 2)
return _____________;
int k= ____________;
// inv: p is not divisible by integers in 2..k-1
while (k != p) {
if ( _________ )
return false;
k= k+1;
}
return ____________;
}
Function 2.
As you know, characters are represented by integers, and the cast (int)c yields the integer that represents c. So, some characters are represented by primes and others are not. Complete the function given on the next page.
Question: How can you check out the function? How do you know that it works?

/** = a String that contains each capital letter (in
     'A'..'Z') whose representation is prime */
public static String primeChars() {
String s= "";
char c= ___;
/** inv: s contains each capital that is less than c and 
       whose representation is prime */
while ( ___ ) {
if ( ___ )
s= s + ___;
c= (char)(c+1);
}
}
Function 3
Write a function with the following specification.
/** = number of times character c appears in String s */
public static int noOfTimes(char c, String s)
For example, since 'e' occurs twice in "where", the following statement stores 2 in x:
x= noTimes('e', "where");
Question: what range of integers does the function process?
Function 4
Write a function with the following specification.
/** = number of times the characters in s1 appear in s2 */
public static int noOfTimes(String s1, String s2)
This function could be used as follows. The call
      	noOfTimes("aeiou", "Where is it?")
yields the number of times a vowel occurs in “Where is it?”. Note that duplicates in s1 are to be counted as many times as they occur in s1. For example,
noOfTimes("aaa", "ac") 
returns 3.
The body of this function should contain a loop that calls the previous function that you wrote (the other function noOfTimes) once for each character in s1. 
Question: what range of integers does the function process?