|
|
javac Hello.java |
Then interpret the error messages (point out the line number in the error message).
Show student how to go to the line in gedit and correct the error.
Then compile again and run the program.
|
|
|
|
You should read the material before coming to the lab. If you have not done so, you will need to read it while the TA is explaining the lab and you can read them after the lab to re-enforce what you have learned.
mkdir ~/cs170/lab2 # Create the lab2 directory inside cs170 cp ~cs170002/share/lab2/* ~/cs170/lab2 # Copy files cd ~/cs170/lab2 # Make lab2 the current directory |
If you do not see the files Convert.java and Cylinder.java, ask the TA for help.
UNIX>> cat Convert.java |
You should see this output:
import java.util.Scanner; /* This program converts km to miles. */ public class Convert { public static void main(String [] args) { // declaration of the variables double km, miles; // create a Scanner Scanner input; input = new Scanner(System.in); // Enter distance in kilometer System.out.print("Please enter a distance in km: "); km = input.nextDouble(); // Read in input from terminal // and stores it in the variable "km" // Calculate distance in miles miles = 0.62 * km; // print out the result System.out.print(km); System.out.print(" kilometers = "); System.out.print(miles); System.out.println(" miles"); } } |
This program reads from the terminal a distance in kilometers and prints the corresponding measure converted in miles.
|
|
|
Add the following to the Cylinder.java program: (the tasks are also given inside the Cylinder.java program with comments (//))
|
|
/home/cs170002/turnin-lab Cylinder.java lab2 |
This makes a copy of your file (Cylinder.java) in the grader's account.
Your turnin is successful when you see this message:
Program `Cylinder.java' has been turned in by YOUR_ID as lab2 |
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.
|
|