Present: Mary-Anne, Matthew, Andrew, Serena, Jiaxing, Henri, Yiwei,
Kevin, Jashan (Jay), Zejun, Rui, Yawen, Ryan, Runxia, Adrian  

So far not here: Bakr, Jingyun, Yiwei, Santiago, Chris 

Read the book: 

Chapter  Purpose 
 1       Writing the first program 
 2       Using Objects (you can't do everything with just primitive types)
 3       Designing Classes (exposed to how we got what we use in Chapter 2)   
 4       What goes in methods (assignment statements, types, values, expressions)
 5       What goes in methods (decision and if statements) 
 6       What goes in methods (loops: while, for, do-while) 
 7       Simple data structures: arrays (one-, two-, three- multi-dimensional) 
 8       This and the next two chapters further reinforce and discuss the 
 9  concepts introduced in chapters 2 and (especially) 3 such as: the class
10  extension mechanism, inheritance, polymorphism, constructor chaining, dynamic
    method lookup, overriding, shadowing of variables, abstract classes, interfaces
    and so on... 

Exam next Thu, relies on material in the first six chapters. 

First exam from last year with answers posted 

Java programs are made out of classes. 

Classes are containers. They contain members. 

Members can be: static or non-static. 

Members can be: variables or procedures (methods). 

Classes also contain a blueprint (made of all non-static members). 

https://images-na.ssl-images-amazon.com/images/I/41yW2mu%2BXhL.jpg

If you instantiate a class you have an object. 

public class Account {
   
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> new Account()
Account@734f730a
> new Account()
Account@62f69684
> Account a = new Account()
> a
Account@3ca3de78


--------------------------------------------------------

public class Account {
  String name; 
  int balance; 
  
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Account a = new Account()
> a.name
null
> a.balance
0


--------------------------------------------------------

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Account a = new Account()
> a.name
null
> a.balance
0
> a.name = "Jay"
"Jay"
> a.name
"Jay"
> Account b = new Account()
> a.name
"Jay"
> b.name
null
> b.name = "Jiaxing"
"Jiaxing"
> a.name
"Jay"
> b.name = "Jiaxing"
"Jiaxing"


--------------------------------------------------------

Every class comes with a no-arg default constructor. 

You can define your own constructors. You get what you define. 

public class Account {
  String name; // owner
  int balance; 
  Account(String name, int balance) {
    this.name = name;
    this.balance = balance; 
  }  
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Account b = new Account()
Static Error: No constructor in Account matches this invocation
    Arguments: ()
    Expected return type: Account
    Candidate signatures: Account(String, int)
> Account b = new Account("Jay", 3)
> Account a = new Account("Rui", 5)
> a
Account@54cfbee1
> a.name
"Rui"
> b
Account@15cb2400
> b.name
"Jay"


--------------------------------------------------------

public class Account {
  private String name; // owner
  private int balance; 
  Account(String owner, int initial) {
    name = owner;
    balance = initial; 
  }  
  public void deposit(int amount) {
    balance = balance + amount; 
    System.out.println( this.name + "'s balance just became: " + this.balance ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Account a = new Account("Rui", 5)
> a.deposit(2)
Rui's balance just became: 7
> a.deposit(-4)
Rui's balance just became: 3
> Account b = new Account("Jay", 3)
> b.deposit(1)
Jay's balance just became: 4
> a.deposit(1)
Rui's balance just became: 4
> b.deposit(1)
Jay's balance just became: 5


--------------------------------------------------------

public class Account {
  static int howMany; // initialized to 0 (zero) 
  private String name; // owner
  private int balance; 
  Account(String owner, int initial) {
    name = owner;
    balance = initial; 
    System.out.println("Account for " + owner + " created."); 
    System.out.println("It has an initial balance of " + initial); 
    Account.howMany = Account.howMany + 1; 
    System.out.println("It is account number " + Account.howMany + "\n----\n"); 
  }  
  public void deposit(int amount) {
    balance = balance + amount; 
    System.out.println( this.name + "'s balance just became: " + this.balance ); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Account b = new Account("Jay", 3)
Account for Jay created.
It has an initial balance of 3
It is account number 1
----

> Account a = new Account("Rui", 5)
Account for Rui created.
It has an initial balance of 5
It is account number 2
----



A static member belongs to the class not to individual instances. 

You have a static member (and no more than one of it) from when the class is created.

If you create 0, 1, 3, 231 objects there's still one such static member. 

static members belong to the factory not to individual objects. 

https://www.cs.indiana.edu/classes/c212/sum2018/zo.pdf

The reason behind the .pdf above: problem P3.7 in the book (page 126)

https://www.cs.indiana.edu/classes/c212-dgerman/fall2016/resources/rctmpx/3534.html

import javax.swing.JFrame; 

public class Thursday {
  public static void main(String[] args) {
    JFrame a = new JFrame();  
    // System.out.println( a ); 
    a.setVisible( true ); 
    a.setSize( 300, 200 ); 
    // https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.AccessibleJFrame.html
    
  }
}

What else? 

Let's look at JComponent

https://www.youtube.com/watch?v=8zMCzHYOk4U

import javax.swing.JComponent; 
import java.awt.Color; 
import java.awt.Graphics; 

public class Contestant extends JComponent {
  public void paintComponent(Graphics g) {
    g.setColor(Color.BLUE); 
    g.drawString("My name is Gattis Kandis.", 100, 150);  
  }
}

import javax.swing.JFrame; 

public class Thursday {
  public static void main(String[] args) {
    JFrame a = new JFrame();  
    // System.out.println( a ); 
    a.setVisible( true ); 
    a.setSize( 300, 200 ); 
    // https://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.AccessibleJFrame.html
    a.add(new Contestant()); 
  }
}

--