This part of the lab is highly synchronized:
|
|
Let students find the error and correct it. Help them understand the logical error.
|
|
You should read the material before coming to the lab.
If you have not done so, try to following the instructions in this webpage (they are very detailed and self-explanatory).
You should read the webpages above after the lab to re-enforce what you have learned.
|
mkdir ~/cs170/lab6
cp ~cs170002/share/lab6/* ~/cs170/lab6
cd ~/cs170/lab6
|
bluej & |
|
(If you need detailed instruction on how to open a directory as BlueJ project, please see lab3.)
|
|
|
|
TA:
|
|
The IsPrime.java has a logical error.
You must find and correct the logical error
TA should discuss briefly how to determine when a number is prime:
x = 5
First: Assume x is prime
5 % 2 remainder = 1 x is still prime
5 % 3 remainder = 2 x is still prime
5 % 4 remainder = 1 x is still prime
DONE ===> x (5) is prime
|
|
|
(TA: let each student find out the problem for himself/herself. But assist the students and show them what to do if they ask.)
You will see the following code:
/* ----------------------------------------------------------------
Complete the method "toUpperCase()"
---------------------------------------------------------------- */
public class UpperCase
{
public static String toUpperCase( String s )
{
String output;
output = "";
// For each character in input string s, do:
// {
// if character is a lowercase:
// append the uppercase character to output
// otherise
// append the character to output
// }
// Don't forget the return the output !!!
}
/* ------------------------------------------------------
Method main is our main entry point.
------------------------------------------------------ */
public static void main(String args[])
{
String in, out;
in = "Hello4";
out = toUpperCase(in);
System.out.println("Input: " + in + "\tUppercased Output: " + out);
in = "7*h$npo";
out = toUpperCase(in);
System.out.println("Input: " + in + "\tUppercased Output: " + out);
}
}
|
The method toUpperCase contains an input variable s which holds the input string.
Write statements inside the toUpperCase method that changes all the lower case letters in the input variable s into upper case. Do not change characters that are not lower case letters.
After converting the characters, the method must return the result.
I want to show you an example here on how it will work:
Suppose the input string is:
s = "Hello4"
The variable output will contain the result.
We start with:
output = "";
|
cd ~/cs170/lab6 /home/cs170002/turnin-lab Mystery.java lab6 /home/cs170002/turnin-lab IsPrime.java lab6a /home/cs170002/turnin-lab UpperCase.java lab6b |
For the Lead TA:
|