CMSC 10200: Lab 1
Wednesday, June 22, 2005
<-- back
Things You Need To Do Once
-
Add the following two lines of code to your .bashrc file:
JAVABIN="/opt/java2/SunJava2-1.4.2_03/bin"
export PATH="$JAVABIN:$HOME/local/bin:$HOME/bin:$PATH:."
This will ensure that you're using the correct
version of Java for this course.
-
Add the following text to your .emacs file:
(set-background-color "white")
-
Make five directories inside your home directory: lab1,
lab2, lab3, lab4 and lab5.
This week's exercise: practice writing some simple functions (methods) in Java
In this lab you will write functions very much like the Java fragments
you've seen in class.
A necessary technicality of this exercise is that you must include the
word static before your function headers. Whereas the Java
fragments presented in class looked like
boolean isZero(int n) {
return (n==0);
}
today you will write them as
static boolean isZero(int n) {
return (n==0);
}
We will create a framework for today's exercise as a group. Within that framework,
develop the following functions:
- abs, which takes an integer and produces its absolute value
- max2, which takes two integers and returns the larger
- min2 (similar to max2)
- mean2, which takes two integers and returns a double
- gcd, as given in class
- isEven, which takes an integer and returns a boolean
- isOdd (similar to isEven)
- isNonNegative, which takes an integer and returns a boolean
- digit2english, which takes an integer between 0 and 9 and
returns the English word for that integer (for example 1 -> "one")
If you have time, proceed to the following functions:
- hypotenuse, which takes two doubles and returns a double
- max3
- min3
- med3
- isPythagoreanTriple, which takes three integers and returns a boolean
- digits, which takes an integer and returns the number of
digits in that integer
OR, alternatively, write the functions
- hexdigit, as in class
- hexpair, as in class
- colorCode, which takes three integers and returns the
HTML-style color code (as in 255,255,0 -> #FFFF00)
You will test each function as you write it, per the instructions
given in lab.
When you're finished, submit the whole lab1 folder by typing
hwsubmit cs102 lab1
at the command prompt.