This lab will require you to have a very good understanding of the introductory chapters to JAVA.
MAKE SURE YOU HAVE READ AND UNDERSTAND CHAPTERS 2 AND 3 in GREAT IDEAS IN COMPUTER SCIENCE
Turn in written answers to all of the indicated questions in each section as your prelab
You will have a Unix "quiz" that will count towards your lab grade at the beginning of lab period. Make sure you are familiar with Unix commands.
Unix Basics
Make sure that you know more than just what the commands do. You should be able to use them in a logical combination to follow such instructions as:
Make a lab5 folder in your cps001 directory.
Copy files to display your lab 3 files on the web
The UNIX quiz will count as 2 points for your grade on this lab.
There are some things which the tutorial above does not cover,
but which you need to know to work comfortably in Unix.
When you are working in Unix, you are always working in some
directory. A directory in Unix is exactly like a folder in
Windows. To find the directory you are currently in, use
pwdpwd is short for 'present working directory'. If you do pwd in your home directory, which is the default working directory after you log into Unix through F-secure, etc., you should see something like
/afs/acpub.duke.edu/users/m/m/xyz123where xyz123 is your acpub id. /afs/acpub.duke.edu/users/m/m/xyz123 is the name of your home directory. Notice that it begins with a forward slash. There are two ways to use a directory name. Directory names that begin with forward slashes are absolute. Directory names that do not begin with a slash are relative to the present directory. You have a cps001 directory in your home directory. There are two ways to get into it:
cd /afs/acpub.duke.edu/users/m/m/xyz123/cps001
cd cps001The first, because it is absolute, works no matter which directory you execute it in. The second, because it is relative, only works from your home directory because the cps001 directory is inside the home directory.
cd ~xyz123/cps001instead of
cd /afs/acpub.duke.edu/users/m/m/xyz123/cps001You can use ~xyz123 instead of /afs/acpub.duke.edu/users/m/m/xyz123 for any Unix command, not just cd.
cd ..in your cps001 directory, you go to your home directory. If you use the same command in your lab1 directory, you go to your CPS001 directory. If you do
cd .in some directory, you stay in that directory.
(a) cd (cd by itself)
(b) cd . (cd followed by a period)
cp ~/cps001/lab4/HelloWorld.java
submit_cps001 lab4/sec2 DecisionTree.*
Read the debugging handout distributed in lecture and found below.
DebuggingIt has a lot of useful advice as to how to go about debugging your code in a systematic fashion. Once again, make sure you have read chapters 2 and 3 so that you are familiar with most of the JAVA rules. Errors arise mostly when these rules are not followed.
1by2F = new TextField(20);
One_by_Two = new TextField(20);
averageF=new Int Field(4);
int i = 17
int j= j +1;
qF.setText(Hello World!);
if(cause==bYes) avgF.setInt(0);
if(cause==bNo) { avgF.setInt(1);
answerF.setInt("100");
You should understand the order in which JAVA operators are applied in an expression. For example, does 8*4+6 equal 38 or 80? Please become fimiliar with precedence of operators such as && and || (logical AND and OR). Also, make sure you understand the difference between logical and bitwise AND and OR. The JAVA tutorial will help you here.
For this lab, you will need to become familiar with the behavior of the mod (%) and div (/) operators in JAVA.
| Command | Explanation |
|---|---|
| % | Modulus calculates the remainder when dividing two numbers Example: 5 % 3 = 2 |
| / | Division: It is important to note that with integer division, numbers are not rounded to the nearest value. Rather, the remainder (or decimals) would just be truncated. Example: 27 / 7 = 3 |
15 % 4
21 / 3
44 / 5
0 && 2 & 9