Please, make sure that you have added the honor code statement at the top of the lab project file Euclid3.java (that you will obtain per instructions below):
/* THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING CODE WRITTEN BY OTHER STUDENTS. _Your_Name_Here_ */ |
Also, make sure that the Euclid3.java is inside your cs170/lab3 directory ( i.e., inside /home/_your_id_here_/cs170/lab3/)
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.
|
If you cannot finish this during the lab time, then it is due by midnight today.
mkdir ~/cs170/lab3
cp ~cs170002/share/lab3/* ~/cs170/lab3
cd ~/cs170/lab3
|
bluej &
|
The ampersand (&) at the end of the command will run BlueJ in the background.
We can still use the Terminal window to enter other commands while BlueJ is running "in the background".
Note:
|
|
Using the terminal application, you can verify that this worked by listing the contents of ~/cs170/lab3 (which you just created). Type this command in a terminal window:
ls ~/cs170/lab3
you should see
FtoC.java along with
a file called
package.bluej.
Important notes on BlueJ:
|
Note:
|
|
Important note:
|
public class Demo
{
/* -------------------------------------
Define the method f(x) = x^2
------------------------------------- */
public static double f( double x )
{
double y;
y = x * x; // square of x
return ( y ); // Return the value y (which is equal to x^2)
}
public static void main(String[] args)
{
double x = 3.0;
double y;
y = f(2.0);
System.out.println(y); // will print 4.0
y = f(x);
System.out.println(y); // will print 9.0
}
}
|
A method returns the computed output value using a return statement:
return ( expression ) ;
|
Example:
public static double FtoC(double x)
{
// input: x = temp in degree in F
// Compute: r = temp in degree C
double r;
// Write these statements:
// 1. compute: x - 32 and store result in variable r
// 2. then multiply r by 5 and store in r
// 3. then divide r by 9 and store in r
// 4. then return r
}
|
Note:
|
Short note on using the BlueJ editor:
|
(Note the editor will help you do indentation semi-automatically, if you let it.)
|
If problems remain, go back and edit again.
|
Note:
|
cd ~/cs170/lab3
/home/cs170002/turnin-lab FtoC.java lab3
|
This makes a copy of your work (FtoC.java this
time). It does not
check your work for correctness.
Your turnin is
successful
when you see
this message:
Program `FtoC.java' has been turned in by YOUR_ID as lab3
You may "turnin" multiple times ---- a later turnin will overwrite you previous turnin version. So only your last version will be graded.
For the Lead TA:
|
Additional exercise: if you are serious about becoming a Computer Science major, do the additional exercise to hone your editing and programming skills.
Write at the place indicated program statement to exchange the values in the variables x and y
|
|