nelson series talk wed, 11/10 7:00 pm security, liberties and trade-offs in the war on terrorism...

58
Nelson Series Talk Wed, 11/10 7:00 pm rity, Liberties and Trade-offs in the War on Terror Since 9/11, we have enacted the Patriot Act, tighter screening at airports, a proposed national I.D. card system, a color-coded national alert system, irradiated mail, and a Department of Homeland Security, but do all of these things really make us any less vulnerable to another terrorist attack? Security expert Bruce Schneier evaluates the systems that we have in place post-9/11, revealing which of them actually work and which ones are simply "security theater." Learn why most security measures don't work and never will, why bad security is worse than none at all, and why strong security means learning how to fail well. Most of all, learn how you can take charge of your own security - personal, family, corporate, and national. Bruce Schneier http://www.counterpane.com/ http://www.schneier.com/ Bruce Schneier is an internationally renowned security expert. He is the author of eight books--including the best sellers "Beyond Fear: Thinking Sensibly about Security in an Uncertain World," "Secrets and Lies," and "Applied Cryptography"--as well as the Blowfish and Twofish encryption algorithms. His influential

Upload: gertrude-leslie-gilmore

Post on 12-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Nelson Series TalkWed, 11/10 7:00 pm

Security, Liberties and Trade-offs in the War on Terrorism

Since 9/11, we have enacted the Patriot Act, tighter screening at airports, a proposed national I.D. card system, a color-coded national alert system, irradiated mail, and a Department of Homeland Security, but do all of these things really make us any less vulnerable to another terrorist attack? Security expert Bruce Schneier evaluates the systems that we have in place post-9/11, revealing which of them actually work and which ones are simply "security theater." Learn why most security measures don't work and never will, why bad security is worse than none at all, and why strong security means learning how to fail well. Most of all, learn how you can take charge of your own security - personal, family, corporate, and national.

Bruce Schneier

http://www.counterpane.com/http://www.schneier.com/

Bruce Schneier is an internationally renowned security expert. He is the author of eight books--including the best sellers "Beyond Fear: Thinking Sensibly about Security in an Uncertain World," "Secrets and Lies," and "Applied Cryptography"--as well as the Blowfish and Twofish encryption algorithms. His influential newsletter, Crypto-Gram, is read by over 100,000 people.

Page 2: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Week 10 in CS 5

• HW 10 (2 problems)M/T sections

W/Th sections

due Sunday, 11/7 at midnight

due Monday, 11/8 at midnight

Caution: This is very new stuff… Come to recitation (Fri @ 8) for help!

Object-oriented programming

We’re breaking out of the CS5App class

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

Hw10 Pr1: Connect Four Hw10 Pr2: Virtual Art!

Midterm #2 next Friday,

11/12

PAIR

Lab: A-L

Wolfgang Puck: not an object-oriented

chef!

Page 3: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Gaussian Elimination

public static void solve(double[][] A){ for (int c=0 ; c<A[0].length-1 ; ++c) // columns { multRow( A, c, 1/A[c][c] ); // diag = 1.0

for (int r=0 ; r<A.length ; ++r) // rows { if (c != r) // off-diagonal elements become 0.0 { addMxRaToRb( A, -A[r][c], c, r ); } }

}

}

destrow

destrow

sourcerow

multiplier

multiplier

Page 4: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Arrays: the good and bad

+

-

lots of computer work for little programmer work!

Not everything is a bunch of identical boxes!

only one built-in capability: length

you have to use the array’s naming convention A[r][c]

Classes and Objects take care of all 3 drawbacks...

int[] int int intA A[0] A[1] A[2]

Page 5: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Classes & Objects

An object-oriented programming language allows you to build your own customized types of variables.

(1) A class is a type of variable.

(2) An object is one such variable.

Page 6: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

But Why ?

• Flexibility

• Reusability

• Abstraction

ordinary data structures

create-your-own

write once, take anywhere

worry once, use anywhere

Page 7: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Java’s Library of Classes

java.sun.com/j2se/1.4.2/docs/api/index.html

~ 3000 classes

available

details on the data and methods that each class offers…

Page 8: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coursec

void addStudent(String s)

String

String[]

doubleint

name

npeople

clist

hours

int numStudents()

String String

Names!

Objects

An object is a data structure (like an array), except

(1) Its data elements need not be the same type.

(2) Its data elements have names chosen by the programmer.

(3) Its data can be protected from unauthorized changes!

(4) An object can have behaviors built-in by the programmer.

Page 9: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

if (s.equals(“I’m an object!”))

{

s2 = “Ask me to do something!”;

}

int L = s2.length();

char c = s2.charAt(22);

the equals method is a built-in capability of String objects

You’ve done all this before...

the dot indicates selection or containment

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

String s = “I’m an object!”;

String s2 = “I’m another object!”;

nonstatic methods are called by an object

another nonstatic method

static methods are called by a class, e.g. Math.sqrt(d);

Page 10: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Classes v Objects: some examples

(1) A class is a type of variable.

String s = “I’m an object!”;

(2) An object is such a variable.

the classes are in blue the objects are in green

Board b = new Board(6,7);

Date d = new Date(11,13,2004);

special constructor methods used with new

Course c = new Course(“cs5”);

Course c2 = new Course(“chem”);

Date d2 = new Date(11,25,2004);

Strings are used so much new is not required…

Page 11: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coding classes and objects: in main

Coursec

void addStudent(String s)

String[]

doubleintnpeople

clist

hours

int numEnrolled()

String String

Course(String name)

data

methods

“constructor”

public static void main(String[] args){ Course c = new Course(“cs5”); // construct c c.addStudent(“Michael”); // add a student H.pl(c.numEnrolled()); // print enrollment: 1

Stringname

Page 12: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class Course{ private String name; private int npeople; private double hours; private String[] clist;

public Course(String n) { this.name = n; this.clist = new String[42]; this.npeople = 0; this.hours = 3.0; }

public void addStudent(String s) { this.clist[npeople++] = s; }

public int numEnrolled() { return this.npeople; }}

data members

constructor

methods

Coding classes and objects: in Course

Page 13: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class Course{ private String name; private int npeople; private double hours; private String[] clist;

public Course(String n) { this.name = n; this.clist = new String[42]; this.npeople = 0; this.hours = 3.0; }

public void addStudent(String s) { this.clist[npeople++] = s; }

public int numEnrolled() { return this.npeople; }}

data members

the object being constructed

data protection !

constructor

refers to the object calling the method

methods

Coding classes and objects: in Course

Page 14: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coursec2

public static void main(String[] args){ Course c = new Course(“cs5”); // construct c c.addStudent(“Michael”); // add a student to c

Course c2 = new Course(“chem”); // construct c2 c2.addStudent(“Marie”); // add a student to c2

Two (or more) objects of the same class…

Coursec

Page 15: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class Course{ private String name; private int npeople; private double hours; private String[] clist;

public Course(String n) { this.name = n; this.clist = new String[42]; this.npeople = 0; this.hours = 3.0; }

public void addStudent(String s) { this.clist[npeople++] = s; }

public int numEnrolled() { return this.npeople; }}

data members

constructor

methods

Coding classes and objects: in Course

this is sort of a pain…

Page 16: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

this is optional !

class Course{ private String name; private int npeople; private double hours; private String[] clist;

public Course(String n) { name = n; clist = new String[42]; npeople = 0; hours = 3.0; }

public void addStudent(String s) { clist[npeople++] = s; }

public int numEnrolled() { return npeople; }}

data members

constructor

methods

but it is always there…

Page 17: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Connect Four

For your convenience, the creators of Java’s library have included a Board class that can represent any size Connect Four board... !

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 60 1 2 3 4 5 6

0

1

2

3

4

5

0

1

2

3

4

5

Page 18: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Connect Four: class Board , object b

This is true for sufficiently broad definitions of “the creators of Java’s library” ...

Boardb

void addMove(int c, char player)

intnrows

intncols

boolean allowsMove(int c)

char char char

char char char

char char char

datachar[][] char

char

char

Page 19: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Board

Starting code for a Board class and CS5App class is in Hw10Pr1.zip

class Board{ private int nrows; private int ncols; private char[][] data;

public Board(int R, int C) { this.nrows = R; this.ncols = C; this.data = new char[nrows][ncols];

for (int r=0 ; r<this.nrows ; ++r) for (int c=0 ; c<this.ncols ; ++c) this.data[r][c] = ‘ ’; }

public void addMove(int c, char player) …

public boolean allowsMove(int c) …

3 data members

constructor

methods

Page 20: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class CS5App{ public static void main(String[] args) { H.pl(“Hi! Welcome to Connect 4…”); int R = H.ni(“How many rows?(4-15)”); int C = H.ni(“How many columns? (4-15)”);

Board b = new Board(R,C); char player = 'X';

while (true) { b.print(); int uc = H.ni(player + “'s move:”);

while ( !b.allowsMove(uc) ) uc = H.ni(player + “'s move:”); b.addMove(uc,player);

if (player == 'X') player = '0'; else player = 'X'; } // end of while } // end of main} // end of class CS5App

“Quiz”What is each

portion of main doing?

1

2

3

4

What still needs to be done?

Page 21: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class Board{ private int nRows; private int nCols; private char[][] data;

// constructor and other methods here

public void addMove(int c, char player) { for (int r=this.nRows-1 ; r>=0 ; --r) { if (this.data[r][c] == ‘ ’) { this.data[r][c] = player; break; } } } public boolean allowsMove(int c) {

}}

What is each line of addMove doing?

Write allowsMove . It should return true if c is OK for a

move; false otherwise.

1

2

3

4

“Quiz,” part 2

Page 22: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 1

Similar to Lights Out and Life, but using a Board object:

main

class CS5App

sets things up and runs a large while loop

class Board

Board

allowsMove

print

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw10 Pr1: Connect Four

(1) Get the # of rows and cols (R, C)

(2) Create an object, b, of type Board

(3) Big while loop...

(1) Ask for the next player’s move

(2) Check the move & then make it

(3) See if the game is over

Board b = new Board(R,C);

Page 23: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 1

Similar to Lights Out and Life, but using a Board object:

main

class CS5App

sets things up and runs a large while loop

class Board

Board

allowsMove

print

addMove

isFull

winsFor

the “constructor”

checks if allowed

places a checker

outputs to screen

checks if space left

checks if a player has won

Hw10 Pr1: Connect Four

(1) Get the # of rows and cols (R, C)

(2) Create an object, b, of type Board

(3) Big while loop...

(1) Ask for the next player’s move

(2) Check the move & then make it

(3) See if the game is over

Board b = new Board(R,C);QUIZQUIZ

still to do…

Page 24: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 1

Still to write in the Board class:

public boolean isFull()

public boolean winsFor(char pl)

1

2

Extra Credit: Mouse input

Page 25: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 2

Similar to previous menu problems, but using Date objects:

(0) Enter a new date of interest(1) Print the current date of interest(2) Move one day forward in time(3) Move one day backward in time(4) Day difference finder(5) Find the day of the week

(9) Quit

main

class CS5App

sets things up and runs a large while loop

printMenu prints

Methods

Hw10 Pr2: The Date Calculator

Pair Programming

Problem

Page 26: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 2

Similar to previous menu problems, but using Date objects:

(0) Enter a new date of interest(1) Print the current date of interest(2) Move one day forward in time(3) Move one day backward in time(4) Day difference finder(5) Find the day of the week

(9) Quit

main

class CS5App

sets things up and runs a large while loop

printMenu prints

Methods

Hw10 Pr2: The Date CalculatorPAIR

no computer required…

Prof. Art Benjamin

Page 27: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 2

Similar to previous menu problems, but using Date objects:

(0) Enter a new date of interest(1) Print the current date of interest(2) Move one day forward in time(3) Move one day backward in time(4) Day difference finder(5) Find the day of the week

(9) Quit

main

class CS5App

sets things up and runs a large while loop

class Date

Date

printMenu prints

print

yesterday

tomorrow

isBefore

diff

dayOfWeek

the “constructor”

prints

forward 1 day

backward 1 day

helper method

# of days difference between 2 Dates

returns a String

MethodsMethods

Hw10 Pr2: The Date CalculatorPAIR

diffNoPrint same w/ no printing

Page 28: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Two Date objects: d and d2

intmonth

Dated void print()

intyear

void tomorrow()

intday

intmonth

Dated2 void print()

intyear

void tomorrow()

intday

Page 29: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

The Date classclass Date{ private int month; private int day; private int year;

public Date(int m, int d, int y) { this.month = m; this.day = d; this.year = y; }

public void print() { H.p(this.month + “/”); H.p(this.day + “/”); H.p(this.year); }}

data members

method

constructor

Page 30: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Making a new Date

class CS5App{ public static void main(String[] args) { Date d = new Date(11,13,2004); Date d2 = new Date(11,25,2004); H.p(“The ACM contest is on ”); d.print();

d.tomorrow();

H.p(“CS 5’s midterm is due on ”); d.print();

H.p(“And Thanksgiving will be ”); d2.print(); }}

Page 31: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Making a new Date

class CS5App{ public static void main(String[] args) { Date d = new Date(11,13,2004); Date d2 = new Date(11,25,2004); H.p(“The ACM contest is on ”); d.print();

d.tomorrow();

H.p(“CS 5’s midterm is due on ”); d.print();

H.p(“And Thanksgiving will be ”); d2.print(); }}

11/13/2004

Output

Page 32: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Making a new Date

class CS5App{ public static void main(String[] args) { Date d = new Date(11,13,2004); Date d2 = new Date(11,25,2004); H.p(“The ACM contest is on ”); d.print();

d.tomorrow();

H.p(“CS 5’s midterm is due on ”); d.print();

H.p(“And Thanksgiving will be ”); d2.print(); }}

11/13/2004

Output

11/14/2004

Page 33: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Making a new Date

class CS5App{ public static void main(String[] args) { Date d = new Date(11,13,2004); Date d2 = new Date(11,25,2004); H.p(“The ACM contest is on ”); d.print();

d.tomorrow();

H.p(“CS 5’s midterm is due on ”); d.print();

H.p(“And Thanksgiving will be ”); d2.print(); }}

11/13/2004

Output

11/14/2004

11/25/2004

Page 34: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

tomorrow()class Date{ public void tomorrow() {

}}

intday

intyear

intmonth

data members in every Date

Page 35: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Checking a Date

class CS5App{ public static void main(String[] args) { // prompt the user for mo, dy, yr: int mo = H.ni(); int dy = H.ni(); int yr = H.ni();

Date d = new Date(mo,dy,yr); if (d.isLeapYear()) H.pl(“d has 366 days”); else H.pl(“d has 365 days”); } }

Page 36: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Leap years

class Date{ public boolean isLeapYear() { if (this.year % 400 == 0) return true;

if (this.year % 100 == 0) return false;

if (this.year % 4 == 0) return true;

} }

intday

intyear

intmonth

only one of these is needed here…

Page 37: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Comparing Dates

class CS5App{ public static void main(String[] args) { Date d = new Date(11,13,2004); Date d2 = new Date(11,25,2004); if (d.isBefore(d2)) H.pl(“d is earlier than d2”);

else H.pl(“d is not earlier than d2”);

}}

Page 38: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Comparing Dates

class Date{ public boolean isBefore(Date d2) {

} }

What two dates are being compared here?

d2 is only one of them!

Page 39: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 2 “Tricks”

public int diff(Date d);returns the # of days between this and d

• positive if d is after this• negative if d is before this• print every day in between!

public String dayOfWeek();returns the day of the week on which this falls

Page 40: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Summary/Examples

An object is a variable.

Objects are created via new and a constructor.

A class is a type of variable.

A class can include both data members and methods.

The object that calls a method is named this inside that method.

class Date{ private int month; private int day; private int year;

public Date(int m, int d, int y) { this.month = m; this.day = d; this.year = y; }

public void print() { H.p(this.month + “/” + this.day + “/” + this.year); }}

Date d = new Date(11,10,2003);

Page 41: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Lab this week

• Problem 2: The Date Calculator (Pairs)

You’ll need to write (and use)

• Problem 1: Connect 4 !

• Extra Credit: Mouse input-handling for Connect Four

Last Names A-L

DateprinttomorrowyesterdayisBeforediffdiffNoPrintdayOfWeek …

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| | |--------------- 0 1 2 3 4 5 6

isFull

winsFor

allowsMove

Page 42: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Example contest problem

Factorial Factors - Southern California Regional ACM Programming ContestThe factorial function, n! = 1 · 2 · ... · n, has many interesting properties. In this problem, we want to determine the maximum number of integer terms (excluding 1) that can be used to express n!. For example: 8! = 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 = 2 · 3 · 2 · 2 · 5 · 3 · 2 · 7 · 2 · 2 · 2 = 27 · 32 · 5 · 7By inspection, it is clear that the maximum number of terms (excluding 1) that can be multiplied together to produce 8! is 11.

The input for your program consists of a series of test cases on separate lines. Each line contains one number, n, 2 <= n <= 1000000. For each test case, print the maximum number of factors (excluding 1) that can be multiplied together to produce n!. Put the output from each test case on a separate line, starting in the first column.

Sample Input21000000199658123456

Sample Output136266195957511426566

Page 43: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Objects

An object is a data structure (like an array), except

(1) Its data elements need not be the same type.

(2) Its data elements have names chosen by the programmer.

(3) Its data can be protected from unauthorized changes!

(4) An object can have behaviors built-in by the programmer.

Coursec

void addStudent(String s)

String

String[]

doubleint

name

number

students

hours

int numStudents()

String String

Names!

the dot is used to get at parts of an object

(data or actions)

Page 44: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

slides to print following this…

Page 45: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Gaussian Elimination

public static void solve(double[][] A){ for (int c=0 ; c<A[0].length-1 ; ++c) // columns { multRow( A, c, 1/A[c][c] ); // diag = 1.0

for (int r=0 ; r<A.length ; ++r) // rows { if (c != r) // off-diagonal elements become 0.0 { addMxRaToRb( A, -A[r][c], c, r ); } }

}

}

destrow

destrow

sourcerow

multiplier

multiplier

Page 46: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coursec

void addStudent(String s)

String

String[]

doubleint

name

npeople

clist

hours

int numStudents()

String String

Names!

Objects

An object is a data structure (like an array), except

(1) Its data elements need not be the same type.

(2) Its data elements have names chosen by the programmer.

(3) Its data can be protected from unauthorized changes!

(4) An object can have behaviors built-in by the programmer.

Page 47: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coding classes and objects: in main

Coursec

void addStudent(String s)

String[]

doubleintnpeople

clist

hours

int numEnrolled()

String String

Course(String name)

data

methods

“constructor”

public static void main(String[] args){ Course c = new Course(“cs5”); // construct c c.addStudent(“Michael”); // add a student H.pl(c.numEnrolled()); // print enrollment: 1

Stringname

Page 48: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Connect Four

For your convenience, the creators of Java’s library have included a Board class that can represents any size of Connect Four board... !

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| |O|--------------- 0 1 2 3 4 5 60 1 2 3 4 5 6

0

1

2

3

4

5

0

1

2

3

4

5

Page 49: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class CS5App{ public static void main(String[] args) { H.pl(“Hi! Welcome to Connect 4…”); int R = H.ni(“How many rows?(4-15)”); int C = H.ni(“How many columns? (4-15)”);

Board b = new Board(R,C); char player = 'X';

while (true) { b.print(); int uc = H.ni(player + “'s move:”);

while ( !b.allowsMove(uc) ) uc = H.ni(player + “'s move:”); b.addMove(uc,player);

if (player == 'X') player = '0'; else player = 'X'; } // end of while } // end of main} // end of class CS5App

“Quiz”What is each

portion of main doing?

1

2

3

4

What still needs to be done?

Page 50: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

class Board{ private int nRows; private int nCols; private char[][] data;

// constructor and other methods here

public void addMove(int c, char player) { for (int r=this.nRows-1 ; r>=0 ; --r) { if (this.data[r][c] == ‘ ’) { this.data[r][c] = player; break; } } } public boolean allowsMove(int c) {

}}

What is each line of addMove doing?

Write allowsMove . It should return true if c is OK for a

move; false otherwise.

1

2

3

4

“Quiz,” part 2

Page 51: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 1

Still to write in the Board class:

public boolean isFull()

public boolean winsFor(char pl)

1

2

Extra Credit: Mouse input

Page 52: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Two Date objects: d and d2

intmonth

Dated void print()

intyear

void tomorrow()

intday

intmonth

Dated2 void print()

intyear

void tomorrow()

intday

Page 53: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

tomorrow()class Date{ public void tomorrow() {

}}

intday

intyear

intmonth

data members in every Date

Page 54: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Leap years

class Date{ public boolean isLeapYear() { if (this.year % 400 == 0) return true;

if (this.year % 100 == 0) return false;

if (this.year % 4 == 0) return true;

} }

intday

intyear

intmonth

only one of these is needed here…

Page 55: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Comparing Dates

class Date{ public boolean isBefore(Date d2) {

} }

What two dates are being compared here?

d2 is only one of them!

Page 56: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Problem 2 “Tricks”

public int diff(Date d);

returns the # of days between this and d

• positive if d is after this• negative if d is before this• print every day in between!

public String dayOfWeek();returns the day of the week on which this falls

Page 57: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Lab this week

• Problem 2: The Date Calculator (Pairs)

You’ll need to write (and use)

• Problem 1: Connect 4 !

• Extra Credit: Mouse input-handling for Connect Four

Last Names A-L

DateprinttomorrowyesterdayisBeforediffdiffNoPrintdayOfWeek …

| | | | | | | || | | | | | | || | | | | | | || | | |X| | | || |X| |X|O| | ||X|O|O|O|X| | |--------------- 0 1 2 3 4 5 6

isFull

winsFor

allowsMove

Page 58: Nelson Series Talk Wed, 11/10 7:00 pm Security, Liberties and Trade-offs in the War on Terrorism Since 9/11, we have enacted the Patriot Act, tighter screening

Coursec

void addStudent(String s)

String

String[]

doubleint

name

npeople

clist

hours

int numEnrolled()

String String

Course(String name)

data

methods

“constructor”

public static void main(String[] args){ Course c = new Course(“cs5”); // construct c c.addStudent(“Michael”); // add a student H.pl(c.numEnrolled()); // print enrollment: 1

“cs5”

1 3.0

“Micha

el”

Coding classes and objects: in main