Read the textbook. 

Chapter 1, 2 for tomorrow. 

Chapter 3 for Monday. 

Submit assignments in your repositories. 

Try to follow the deadline, don't hesitate to submit late. 

Chapter 4, 5, 6 are fundamental and you may have seen the material before. 

Chapter 2 at the end and Chapter 3: really new.

In this class you write programs in Java. 

Java programs are made of classes. 

Each class has a name, should be public, stored in separate file(s). 

First example: in a file called One.java I have

public class One {
  public static void main(String[] args) {
    System.out.println( 4.53 * 100 ); // expected: 453.00 
  } 
}

Compile (javac One.java) and run (java One) this program. 

Errors: always think about and fix the first one. 

The first error has the most accurate error reporting. 

Is there an exam any time soon? We will seek an answer to that in lab. 

1.7 The Algorithm Concept (C211: Design Recipe) 

Please review all chapters in the book before starting a new chapter. 

1 Tuesday 

1 2 Wednesday 

1 2 3 Thursday 

1 2 3 4 Monday 

1 2 3 4 5 Tuesday 

1 2 3 4 5 6 Wednesday 

First Exam: Thursday? 

Self-check questions as you read; answers are at the end of chapter. 

I would like everybody 

  (a) to log into silo 
  (b) and go into the folder where they have the server 

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

public class Server {

    public static void main(String[] args) throws Exception {
        if (args.length < 1) {
          System.out.println("Call me with a valid port number as argument.\n\nFor example: java Server 27182\n\n");
        } else {
          HttpServer server = HttpServer.create(new InetSocketAddress(Integer.parseInt(args[0])), 0);
          server.createContext("/stableGenius", new MyHandler());
          server.setExecutor(null); // creates a default executor
          server.start();
        }
    }

    static class MyHandler implements HttpHandler {
        @Override
        public void handle(HttpExchange t) throws IOException {
            String response = "The time on silo is: " + new java.util.Date();
            t.sendResponseHeaders(200, response.length());
            OutputStream os = t.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
    }

}

-bash-4.2$ pwd
/u/dgerman/c212-summer2018-workspace/lab01
-bash-4.2$ ls -l
total 4
-rw-r--r-- 1 dgerman faculty 1159 Jun 20 11:58 Server.java
-bash-4.2$ nano -w ~/apache/htdocs/c212/sum2018/0620a.phps
-bash-4.2$

Changes we all need to make:

 (a) determine port (see list) 

 (b) decide on a specific keyword 

 (c) include your name in time report

Make two changes in your code before you recompile:

-bash-4.2$ pwd
/u/dgerman/c212-summer2018-workspace/lab01
-bash-4.2$ grep -n Adrian Server.java
25:            String response = "Adrian reports: " + new java.util.Date();
-bash-4.2$ grep -n luisSuarez Server.java
16:          server.createContext("/luisSuarez", new MyHandler());
-bash-4.2$

Keep the luisSuarez part, but change line 25 to include your name. 

Look up and and take your port number from here: 

https://www.cs.indiana.edu/classes/c212-dgerman/sum2018/ports.html

Did not respond: 

http://silo.cs.indiana.edu:27183/luisSuarez (Bakr, says doesn't like Suarez) 

http://silo.cs.indiana.edu:27192/luisSuarez (Chris, absent)

Servers worked: 

http://silo.cs.indiana.edu:27184/luisSuarez (Kevin) 

http://silo.cs.indiana.edu:27185/luisSuarez (Yiwei) 

http://silo.cs.indiana.edu:27187/luisSuarez (Ryan) 

http://silo.cs.indiana.edu:27188/luisSuarez (Mary Ann)

http://silo.cs.indiana.edu:27189/luisSuarez (Yawen) 

http://silo.cs.indiana.edu:27190/luisSuarez (Jay)

http://silo.cs.indiana.edu:27191/luisSuarez (Serena)

http://silo.cs.indiana.edu:27193/luisSuarez (Jiaxing) 

http://silo.cs.indiana.edu:27194/luisSuarez (Andrew) 

http://silo.cs.indiana.edu:27195/luisSuarez (Zejun) 

http://silo.cs.indiana.edu:27196/luisSuarez (Matthew) 

http://silo.cs.indiana.edu:27197/luisSuarez (Jungyun)

http://silo.cs.indiana.edu:27198/luisSuarez (Runxia) 

http://silo.cs.indiana.edu:27199/luisSuarez (Rui) 

http://silo.cs.indiana.edu:27200/luisSuarez (Adrian)

http://silo.cs.indiana.edu:27201/luisSuarez (Santiago)


Now: simplify those expressions. 

Henri     and Jiaxeng :  a && true 

They say:                a


  a       a && true 
-------------------------
true      true 
false     false end of proof and they were right 


Yawen     and Zejun   :  a || true 

They say:                true 


  a       a || true    true 
----------------------------
true      true         true 
false     true         true end of proof and they were right 


Mary-Anne and Runxia  :  a == false 

They say:                !a


 a       a == false      !a 
--------------------------------
true      false          false 
false     true           true end of proof and they were right 


Ryan      and Jingyun :  a != false 

They say:                true 


 a       a != false      true 
----------------------------------
true     true            true 
false    false           true so there's a mistake here 


What's the right answer here? 

 a       a != false      ?(a) = a
----------------------------------
true     true            true 
false    false           false 

So the right answer is: a

Here's another way:

    a != false 
! ( a == false) 
! (!a )
    a

For the sake of algebra prove and remember: 

  a == false is the same as !a
  a == true                  a
  a != true                 !a
  a && true                  a
  a || true                 true 
  a || false                 a
  a && false                false 
  a || false                 a
  a || !a                   true 
  a && !a                   false 

Later you can use these to simplify larger expressions. 

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