Homework Two  Friday 

Lab Three     Monday 

Exam on Wednesday 

Practice Exam on Monday

There's a difference between being late and procrastinating

The exercises are from My Programming Lab so working through
those should prepare you for the exam. 

Literals, operators, expressions, values, types, variables, 
assignment statements, input/output, objects, methods, main,
class(es), compile and run. eText. 

Class: container, it contains members. Members: static and
non-static. Non-static members are also called instance members.

A member: variable, procedure. 

Classes contain blueprint. A blueprint is a vision. There's just
one static member per class. The blueprint associated with a class
is comprised of all non-static members in that class. From a blueprint
one can create with the operator new any number (0, 1, more...) objects
and each object is just like the blueprint. It's a vision because you
can create objects but if you don't you don't have any. 

Chapter 4: instance variables, constructors, instance methods. 

Chapter 5 and 6: inside your methods you might have to use either
decisions (if statements) or loops (while, for loops) to iterate. 
 
Primitive types in Java: 

  int     double     char      boolean 
  long    float
  short
  byte

Everything else is known as: reference type, user-defined type, classes

There are four types variables in Java:

  local variables

  parameters 

  instance variables

  class (static) variables

3 + 5

3 < 5

if ( ... ) {
  // if the condition is true
  // execute this branch 
} else {
  // if condition is false 
  // execute this branch
}

Any kind of statement can be placed in the branches, 
including other if statements. 

if ( ... ) {
  if ( ... ) {

  } else {

  } 
} else {
  if ( ... ) {
    if ( ... ) {
      if ( ... ) {

      } else {

      } 
    } else {

    } 
  } else {

  }
}

This is really the structure of the leap year program. 

if ( ... ) {



The else is optional 

while ( ... ) {

}

The branch gets executed as long as the condition is true. 

int i = 0; 
while (i < 10) {
  System.out.println( i ); 
  i++;
}

Question from Jake:

int i = 0; 
while (i < 10) {
  System.out.println( i++ ); 
}

Is the code above equivalent with the one above it. 

Answer: yes

for (int i = 0; i < 10; i++) {
  System.out.println( i ); 
}

Basic syntax for for loops:

..[1]..
for ( ..[2].. ; ..[3].. ; ..[5].. ) {
  ..[4]..
}

A for is equivalent to a while and the other way around

..[1]..
..[2]..
while ( ..[3].. ) {
  ..[4]..
  ..[5]..
}

Like in the case of if statements:

  (a) please use curly braces
  (b) you can nest statements

Example: 

import java.util.Scanner; 

class Z {
  public static void main(String[] args) {
    Scanner in; 
    in = new Scanner(System.in); 
    System.out.print("Size: "); 
    int size = in.nextInt();
    for (int line = 0; line < size; line++) {
      for (int column = 0; column < size; column++) {
        if (line == 0 || line == size-1 || line + column == size - 1) {
          System.out.print("* ");  
        } else { 
          System.out.print( "  "); 
        }
      }
      System.out.println(); 
    }
  }
}




import java.util.*; 

class Z {
  public static void main(String[] args) {
    Scanner in; 
    in = new Scanner(System.in); 
    System.out.print("Size: "); 
    int size = in.nextInt();
    for (int line = 0; line < size; line++) {
      for (int column = 0; column < size; column++) {
        if (line == 0 || 
            line == size-1 || 
            line + column == size - 1 || 
            ( line == size/2 && size/3 <= column && column <= 2 * size/3) ){
          System.out.print("* ");  
        } else { 
          System.out.print( "  "); 
        }
      }
      System.out.println(); 
    }
  }
}


Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> java Z
Size:  [DrJava Input Box]
* * * * * * * * * * * 
                  *   
                *     
              *       
            *         
      * * * * *       
        *             
      *               
    *                 
  *                   
* * * * * * * * * * * 
> java Z
Size:  [DrJava Input Box]
* * * * * * * * * * * * * * * * * * * * * 
                                      *   
                                    *     
                                  *       
                                *         
                              *           
                            *             
                          *               
                        *                 
                      *                   
              * * * * * * * *             
                  *                       
                *                         
              *                           
            *                             
          *                               
        *                                 
      *                                   
    *                                     
  *                                       
* * * * * * * * * * * * * * * * * * * * * 

11

21