Java programs are made of classes. 

Classes are containers. 

They contain members. 

Members are static or no static. 

Members are variables or procedures (methods). 

Classes also contain constructors. 

--

Methods are sequences of statements. 

Example of statements: assignments, decisions, loops, function calls.

Assignments have an expression on the right hand side. 

Expressions contain values, operators, variables and maybe function calls. 

Where are the data structures: slices, dictionaries, tuples, lists?

https://www.amazon.com/gp/product/0312430000

-bash-4.2$ cat One.java
import java.util.Scanner;

public class One {
  public static void main(String[] args) {
    int sum = 0, count = 0; // local variables
    Scanner scout = new Scanner(System.in);
    while (true) {
      System.out.print("Type: ");
      String line = scout.nextLine();
      if (line.equals("bye")) {
        break;
      } else {
        int num = Integer.parseInt( line );
        sum = sum + num;
        count = count + 1;
        System.out.println( sum + " / " + count + " = " + ((double)sum/count) );
      }
    }
    // this is where I go if I hit the break statement

  }
}
-bash-4.2$ java One
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Type: 3
3 / 1 = 3.0
Type: 1
4 / 2 = 2.0
Type: 1
5 / 3 = 1.6666666666666667
Type: 2
7 / 4 = 1.75
Type: bye
-bash-4.2$

--

What if you need to write a program like the one above
(collecting an arbitrary number of numbers) and reports
them. Furthermore at the end the numbers should be listed
sorted in ascending (or descending) order. 

Arrays

ArrayList

Chapter 7

Welcome to DrJava.  Working directory is C:\Users\dgerman
> int a = 3
> a
3
> int[] a = new int[6]
> a
{ 0, 0, 0, 0, 0, 0 }
> int[] b = new int[9]
> b
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }


Welcome to DrJava.  Working directory is C:\Users\dgerman
> int a[]
> int[] b
> String c
> c = "nothing"
"nothing"
> c
"nothing"
> c.charAt(0)
'n'
> a = new int[7]
{ 0, 0, 0, 0, 0, 0, 0 }
> a
{ 0, 0, 0, 0, 0, 0, 0 }
> a[2] = -1
-1
> a
{ 0, 0, -1, 0, 0, 0, 0 }
> String d = c.substring(0, 3) + " a t" + c.substring(3);
> d
"not a thing"
> c
"nothing"
> c = c.substring(0, 3) + " a t" + c.substring(3);
> d
"not a thing"
> c
"not a thing"
> c = c.substring(0, 3) + " a t" + c.substring(3);
> d
"not a thing"
> c
"not a t a thing"
>

Welcome to DrJava.  Working directory is C:\Users\dgerman
> int[] a = new int[6];
> a
{ 0, 0, 0, 0, 0, 0 }
> a[a.length - 1] = 3
3
> a
{ 0, 0, 0, 0, 0, 3 }
> a = new int[9];
> a
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> a[a.length - 1] = 3
3
> a
{ 0, 0, 0, 0, 0, 0, 0, 0, 3 }


Welcome to DrJava.  Working directory is C:\Users\dgerman
> int[] a = new int[6];
> a
{ 0, 0, 0, 0, 0, 0 }
> a[0] = 1
1
> a[1] = 3
3
> a[2] = -5
-5
> a
{ 1, 3, -5, 0, 0, 0 }
> a[3] = 10
10
> a
{ 1, 3, -5, 10, 0, 0 }
> a[4] = 16
16
> a
{ 1, 3, -5, 10, 16, 0 }
> a[5] = 19
19
> a
{ 1, 3, -5, 10, 16, 19 }
> a[6] = 19
java.lang.ArrayIndexOutOfBoundsException
> int[] u
> u = new int[7]
{ 0, 0, 0, 0, 0, 0, 0 }
> u
{ 0, 0, 0, 0, 0, 0, 0 }
> u[0] = a[0]
1
> u[1] = a[1]
3
> u[2] = a[2]
-5
> u[3] = a[3]
10
> u[4] = a[4]
16
> u[5] = a[5]
19
> a
{ 1, 3, -5, 10, 16, 19 }
> u
{ 1, 3, -5, 10, 16, 19, 0 }
> u[6] = 8
8
> a = u
{ 1, 3, -5, 10, 16, 19, 8 }
> a
{ 1, 3, -5, 10, 16, 19, 8 }
> a
{ 1, 3, -5, 10, 16, 19, 8 }
> int[] devarshi = Arrays.copyOf(a, a.length + 1)
Static Error: Undefined name 'Arrays'
> int[] devarshi = java.util.Arrays.copyOf(a, a.length + 1)
> devarshi
{ 1, 3, -5, 10, 16, 19, 8, 0 }
> a
{ 1, 3, -5, 10, 16, 19, 8 }
> devarshi[devarshi.length - 1] = -2
-2
> devarshi
{ 1, 3, -5, 10, 16, 19, 8, -2 }
> a = devarshi
{ 1, 3, -5, 10, 16, 19, 8, -2 }
> a
{ 1, 3, -5, 10, 16, 19, 8, -2 }
> a = java.util.Arrays.copyOf(a, a.length + 1)
{ 1, 3, -5, 10, 16, 19, 8, -2, 0 }
> a[a.length-1] = -3
-3
> a
{ 1, 3, -5, 10, 16, 19, 8, -2, -3 }
> a = java.util.Arrays.copyOf(a, a.length + 1)
{ 1, 3, -5, 10, 16, 19, 8, -2, -3, 0 }
> a[a.length-1] = 100
100
> a
{ 1, 3, -5, 10, 16, 19, 8, -2, -3, 100 }


The lab wants you to define three such methods