We will continue to post ahead of time lab and lecture notes. 

Same goes for assignment of all kinds:

(a) attendance is taken in lab

(b) you can leave early or very early

(c) before you leave show us your work

I have DrJava installed. 

I start it. 

I define a class: 

class Jialin {
  
}

Save this in Jialin.java

Compile it with javac or push the button. 

class Jialin {
  public static void main(String[] args) {

  } 
}

Compile and run it, it does. 

Convert meters to miles, feet and inches. 

0.621371 miles in 1,000 meters. 

5280 feet in a mile. 

12 inches in a foot.

Now let's set ourselves up for reading: 

class Jialin {
  public static void main(String[] args) {
    System.out.println("Welcome to this program."); 
    System.out.print("Please enter a number (distance in meters): ");     

    Scanner rex; // [1] 

    rex = new java.util.Scanner(System.in); 

    System.out.println( rex ); 

  } 
}

At this point I should really compile and test this.

Notice that we need java.util.Scanner in line [1] as well. 

So we moved to DrJava and the program became: 

import java.util.*;

class Jialin {
  public static void main(String[] args) {
    System.out.println("Welcome to this program."); 
    System.out.print("Please enter a number (distance in meters): ");     
    Scanner rex = new Scanner(System.in); 
    double distance = rex.nextDouble();
    System.out.println( distance ); 
  } 
}

Here's how my program works on silo:

-bash-4.1$ pico -w 0619.phps
-bash-4.1$ mkdir code
-bash-4.1$ cd code
-bash-4.1$ pico -w Jialin.java
-bash-4.1$ cat Jialin.java
import java.util.*;

class Jialin {
  public static void main(String[] args) {
    System.out.println("Welcome to this program.");
    System.out.print("Please enter a number (distance in meters): ");
    Scanner rex = new Scanner(System.in);
    double distance = rex.nextDouble();
    System.out.println( distance );
  }
}
-bash-4.1$ javac Jialin.java
-bash-4.1$ java Jialin
Welcome to this program.
Please enter a number (distance in meters): 1234567.89
1234567.89
-bash-4.1$


Here's a summary of Scanner commands:

import java.util.*;

class Jialin {
  public static void main(String[] args) {
    Scanner rex = new Scanner(System.in); 
    System.out.print("Name: ");
    String name = rex.nextLine();
    System.out.print( name + " how old are you? Enter age: "); 
    int age = rex.nextInt(); 
    System.out.println( name + " you will be " + (age + 1) + " next year.");    
  } 
}

Question: if you know that the class Math has a static method random with no 
arguments that (when called) produces random numbers between 0 and 1, that is in 
the interval [0, 1) where 0 can be a possible outcome but 1 can't, or won't, can 
you write a program that would produce a random integer in the interval [-50, 50]?

We wrote this as a result:

class Jialin {
  public static void main(String[] args) {
    int number; 
    number = (int) (100 * Math.random() - 50);
    System.out.println( number ); 
    
    System.out.println ( Math.sqrt(23) ); 
    double a = Math.sqrt(23); 
    System.out.println( Math.pow( a, 2 ) ); 
    
    String b = "23"; 
    int c = Integer.parseInt( b ); 
    System.out.println( Math.sqrt( c ) ); 
    System.out.println( b + 5 ); // produces 235
    System.out.println( c + 5 ); // produces 28 
  } 
}

This code answers more questions from the minute paper. 

Last item on today's list of topics: 

-bash-4.1$ pwd
/u/dgerman/apache/htdocs/c212/sum2013/code
-bash-4.1$ ls -ld Jialin.java
-rw-r--r-- 1 dgerman faculty 139 Jun 19 12:51 Jialin.java
-bash-4.1$ cat Jialin.java
class Jialin {
  public static void main(String[] args) {
    System.out.println( args[0] );
    Integer a = 45;
    int b = 46;
  }
}
-bash-4.1$ javac Jialin.java
-bash-4.1$ java Jialin nine six eighty
nine
-bash-4.1$ java Jialin
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
        at Jialin.main(Jialin.java:3)
-bash-4.1$

--