Starting from:

$30

Lab Assignment #1: Basic Computer Skills

CS 140 (Yang) Introduction to Computer Science
Lab Assignment #1 (10 points): Basic Computer Skills

Due Date: see blackboard assignment section

  
Lab Guidelines:

1)    First establish lab pairs, i.e. each of you should find a study partner to form a pair and then sit next to your partner. I encourage you to change your study partner for  different lab assignments.

2)    If you have any questions, try to answer them within the pair before turning to another pair for help. Ask the instructor for help as the last resort.  

3)    Proceed slowly through the exercises and do the best you can.  It may be helpful to check off those exercises you have completed and to make notes or answer questions where required. 
 
 Compiling and running a Java program on login.cpp.edu

This section demonstrates how you can create a Java program file, compile it, and execute it on login.cpp.edu.    
First create a subdirectory cs140 of your login directory by typing the following:
    $ cd
$ mkdir cs140
Now create a file in pico in subdirectory cs140 by typing the following:
$ cd cs140
$ pico Example.java
Now enter the following code into Example.java:  (note: don’t leave out //)
// your name    
    // date
public class Example 
{
   public static void main(String[] args) 
   {
      System.out.print("This is an example Java program");
      System.out.println();
      System.out.println("   ...a very SIMPLE one...");
   }
}
Exit pico and take a look at your newly created file.  It should look like:
$ cat Example.java
// your name
    // date
public class Example 
{
   public static void main(String[] args) 
   {
      System.out.print("This is an example Java program");
      System.out.println();
      System.out.println("   ...a very SIMPLE one...");
   }
}
Now compile the source code with the javac command to produce the java class file.
$ javac Example.java
Note that the file Example.class has been created. Verify it with the ls command.
Now execute the program with the java interpreter.
$ java Example
This is an example Java program
   ...a very SIMPLE one...
$
Congratulations, you have created, compiled, and executed your first Java program!
 
 Exercise 

Step 1: Complete the above step (i.e. edit a file Example.java, compile and run successfully.)
 
Step 2. Generate a script file called Example.txt (note the file extension is .txt, not .java) in subdirectory cs140 with the following steps visible:
  
    $script Example.txt
    $cat Example.java
    $javac Example.java
    $java Example
    $exit
    
Now check to see if Example.txt contains what you want
    $ls 
    Make sure Example.txt file is in the directory
    $cat Example.txt
Make sure Example.txt contains your program code, compilation and run commands and the output.
 

Step 3. (Optional) Use WinSCP to transfer the Example.txt on your computer Desktop

Step 4: Now you are ready to submit Example.txt to your instructor via blackboard: 

1)    Login to Blackboard

2)    Click CS 140  Assignments  Lab Assignments  Lab #1

3)    Click on Browe computer for file attachment
If your script file is in login.cpp.edu directory, click on Computer, click on your login.cpp.edu drive, and click on cs140 directory if applicable, then double click on the file name; if your script file is already transferred to local computer Descktop, just double click on the file name. After attaching the script file, click the Submit button.

Do not copy and paste the contents of the script file into the text box field. You must “attach” the file to your submission.