Worth:10 points
In this assignment we will be examining how the javac compiler works and learn some new Unix commands.
Some simple rules to follow.........
Common compile time errors that most users make include
Once logged in, get into your public_html directory:
cd public_html
If you have not already made subdirectories, do it now (particularly 2 through 4).
Once you have the directories set up for the course, you can then get into your csci111 and lab 2 directory.
cd csci111/lab2
Copy the following java source file, this file contains errors that you will correct. Don't worry we'll walk you though this example...
cp ~amk/courses/csci15a/15a_examples/DrawACircle.java ./.
Don't forget the period slash at the end of the above command. Now try to compile the DrawACircle.java file. You saw how to compile java programs in lab 1. You should expect to see a number of errors. There are 4 compile time errors in the DrawACircle.java program that need to be fixed. The compiler will not catch all the errors at first and it may even report them in the wrong place. So expect to see initially three errors.
Note all lines that start with // are comments and are there to descibe the program and provide detail you and others of what is going on in the code.
The first error reported is
DrawACircle.java:34: ';' expected.
return Math.cos(RadianAngle)
^
This error says that we are missing a semicolon at the end of line 34. Use pico (or WinSCP editor) and add that missing semicolon. (Your compiler might say error on line 35 and point to the }. It is the same error --- basically a ; should be at the end of line 34. So when the compiler gets to line 35 it notes that it sees the curly bracket and yet the code is missing a semicolon.) See this page lab 2 for how to get to a certain line. Save the file and recompile.
The first error should now be gone and now on to the second error.
DrawACircle.java:104: '}' expected. } ^
This error is misleading since the real error is elsewhere in the code.
But it is a simple error to fix. We are missing a curly bracket in our code,
every block of code must begin with a { open curly bracket and end with } a
close curly bracket. Unfortunately the compiler can not tell us where it is
missing but only that one or more is missing. The missing curly bracket is on
line 45.
Count and match up the curly brackets in the ComputeUnitCircle class
and you will see that there is a missing bracket there. This can be a very hard
error to find, since you must search the code and match up all open and closing
curly brackets. Use pico (or WinSCP editor) and add the missing curly bracket and recompile the
file.
Now save your .java class, recompile it, and you will see that new errors have shown up. After this compile you now see:
DrawACircle.java:58: cannot find symbol
symbol: class Applet
public class DrawACircle extends Applet
^
This is a misleading error also since the real problem is not on line 58 but much earlier in the code. The real problem is that the compiler is missing the definition of the Applet class. The problem is that we forgot to import the library that contains the Applet class. So we must add the correct import statement in the import section of the lab (on line 15 or so) of the DrawACircle.java file. Do not remove the other import statement.
import java.applet.*;
^
Then save and recompile the file. There should now be a new error.
DrawACircle.java:89: cannot find symbol
symbol : variable mycircle
location: class DrawACircle
x=(int)(mycircle.ComputeX((double)degrees/180*3.14)*24+25);
^
This is a very simple error and it is even giving us the right line the error is on. The error is that mycircle is misspelled( capitalization is important) and should be changed to myCircle . Fix this error and recompile.
man w
Web Page Submission Required Contents: