The lab will be done in pairs, announced in class.
passwd
on the command line in a terminal window. You
will be asked to type your current password and then
the new password twice. Note that as you are typing your password,
nothing shows up on the screen (as a security measure).cd
followed by the path
to the folder. Use Tab
key for auto-complete.
jEdit &
This will starts
jEdit. You can starts typing your program and use "Save as" to save it
into your folder. Don't forget to name the file the same as the class
in the program and use .java extension.
javac FirstJava.java
(use your
file name instead of FirstJava). If there are
no errors,
run it: java FirstJava
(again, use your file name instead
of FirstJava).
For every method that you write you must have at least three
tests. Some methods require more tests because they need to
handle more different situations.
Make sure that you test for different conditions.
Write your tests before you write your method. Add more tests as
needed.
Write and test a method countChar
that takes a string
and a character (for instance, a letter) and returns the number of
times the character appears in the string. For instance,
countChar("Morris", 'r')
returns 2. The method performs
a case-sensitive comparison ('A' is not the same as 'a').
Write and test a method hasEvenOccurrences
that takes a string
and a character and returns true if the string has an even number of
occurrences of the character and false otherwise.
For instance, hasEvenOccurrences("Morris", 'r')
returns
true and hasEvenOccurrences("Morris", 'M')
returns
false.
Recall that 0 is an
even number.
You may call the method from Problem 1 in your method.
Write and test a method that takes a positive integer number and prints out
all of its pairs of factors. For instance, a
call printFactors(12)
should print:
12 can be factored as:
1 and 12
2 and 6
3 and 4
The format of the output can be different.
Write and test a method that takes a positive integer n and returns a product of two random integers between 1 and n (inclusive). Make sure that zero is not among the numbers that you multiply.
Send the FirstJava.java file with all your comments by email to me: elenam at morris.umn.edu. The subject of the message must be 2101 Lab 2. Make sure to CC your group partner if you worked with another person.