Homework 12 Sun., 11/24 Due Mon., 11/25 Problems (2 of them)

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Towers of Hanoi Move n (4) disks from pole A to pole C such that a disk is never put on a smaller disk A BC ABC.
Programming Methodology (1). Implementing Methods main.
EC-241 Object-Oriented Programming
Homework 6 Due ( MT sections ) ( WTh sections ) about midnight Sun., 10/12 Mon., 10/13 Problems
Intelligent CS 5 ? HW 11 (1 problem !) M/T sections W/Th sections due Sunday, 11/14 at midnight due Monday, 11/15 at midnight Recitation for HW11 -- Friday.
Homework 14 Due ( MT sections ) ( WTh sections ) at midnight Sun., 12/7 Mon., 12/8 Problems
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Recursion!. Can a method call another method? YES.
Homework 4 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/29 Mon., 9/30 Problems
CS 5 HW 12 (2 problems) M/T sections W/Th sections due Sunday, 11/21 at midnight due Monday, 11/22 at midnight Recitation for HW12 -- Friday 8:00am Looking.
CSC 204 Programming I Loop I The while statement.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Chapter 5 Loops.
Homework 11 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/14 Mon., 11/15 Problems
Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems
This week in CS 5 HW 9 (2 problems) M/T sections W/Th sections due Sunday, 11/4 at midnight due Monday, 11/5 at midnight Recitation for HW9 -- Friday 11/2.
Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CS 100Lecture 131 Announcements Exam stats P3 due on Thursday.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Abstract methods and classes. Abstract method A placeholder for a method that will be fully defined in a subclass.
Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
Three kinds of looping structures The while loop The for loop The do (also called the do-while) loop All have equivalent power, e.g., if you can write.
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
EECS 110: Lec 15: Classes and Objects (2)
Practice + Method Xiaozhong Liu
Chapter 8 – Arrays and Array Lists
Introduction to programming in java
CS305J Introduction to Computing
Recursion (Continued)
Computer Programming Methodology Input and While Loop
Nelson Speaker Series Monica Lam, Stanford
More About Objects and Methods CS140: Introduction to Computing 1 Savitch Chapter 6 10/16/13.
CS 302 Week 10 Jim Williams.
Introduction to Computer Programming
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
Defining methods and more arrays
Introduction to Programming
Code Animation Examples
Recursive GCD Demo public class Euclid {
CS2011 Introduction to Programming I Methods (II)
AKA the birth, life, and death of variables.
Take out a piece of paper and PEN.
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 4 Chapter 5 (Loops).
COMPUTER 2430 Object Oriented Programming and Data Structures I
Recursion Problems.
Scope of variables class scopeofvars {
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
CSE 143 Lecture 18 More Recursive Backtracking
Arrays.
22C:21 Problem 2.3 Solution Outline.
Presentation transcript:

Homework 12 Sun., 11/24 Due Mon., 11/25 Problems (2 of them) ( MT sections ) Due Mon., 11/25 ( WTh sections ) Problems (2 of them) http://www.cs.hmc.edu/courses/2002/fall/cs5/week_12/homework.html Tutors available Saturday afternoons Lac Lab Sunday afternoons Lac Lab Sunday evenings Lac Lab and AC Monday evenings Lac Lab and AC M. Beaumont-Gay & M. Yi in LAC E. Flynn, Y.M. Kim, & A. Klose in AC M. Yi, C. Wottawa, & A. Utter in LAC A. Kangas, P. Scott, A. Pipkin in AC

Problem 2 / Final Project A “film database” application: 5 classes class name data member data member type

Self-referential data ? A film database application: class Director class Director { private String fname; private String lname; private FilmDB filmDB; // method skeletons… String fname FilmDB filmDB FilmDB filmDB String lname class Film String rating class Film { // data members // method skeletons String title double review Director int year Director dir dir class FilmDB class FilmDB { // data members // method skeletons int count Film[] films[0] films[1] Film[] films films

Problem 2 - skeleton code Classes Data Members Methods CS5App none public static void main(String[] args) public static void printMenu() Film String title int year String rating double review Director dir public Film(String title, int year, String rating, double review, Director dir) public String getTitle() public int getYear() public String getRating() public double getReview() public void display()

Director DirectorDB FilmDB Classes Data Members Methods Director String fname String lname FilmDB filmDB public Director(String fname, String lname, int capacity) public String getFullName() public FilmDB getFilmDB() public DirectorDB(int capacity) public void displayAllDirectors() public void displayFilmsByDirector(String fname, String lname) public Director findDirectorByName(String fname, String lname) public void addDirector(Director dir) public int getCount() public boolean isFull() DirectorDB int count Director[] dirs FilmDB int count Film[] Films public FilmDB(int capacity) public boolean isFull() public int getCount() public void addFilm(Film f) public Film findFilmByTitle(String title) public void displayAllFilms() public void displayFilmsByTitle(String titlepiece) public void displayFilmsByYear(int year) public void displayFilmsByRating(String rating) public void displayFilmsByReview(double minreview)

Problem 2 Implement the main menu (in the CS5App class) Please choose an action from the following list: 0 Display All Directors 1 Display All Films 2 Display Films by Title 3 Display Films by Director 4 Display Films by Year 5 Display Films by Rating (G, PG, …) 6 Display Films by Review (0 to 10) 7 Add a New Film 9 Quit Create skeleton versions of the necessary classes...

Care to Swap ? Suppose we want to swap the variables x and y … int x = 42; int y = 5; int x int y

Problem 1 - recursion void sort(double[] arr, int L, int H) 80 97 42 75 23 L H

Iterative vs. Recursive void moveMinToLeft(double[] arr, int L, int H) 80 97 42 75 23 L H

Iterative vs. Recursive void moveMinToLeft(double[] arr, int L, int H) 80 97 42 75 23 L H

Swapping Suppose we want to swap the H-1st and the Hth values... 80 97 42 75 23 L H-1 H

Problem 1 - recursion void sort(double[] arr, int L, int H) 80 97 42 75 23 L H

Problem 1 - recursion public static double harmonic(int N)

Problem 1 - recursion public static String reverse(int N)

Ex. Cr. evaluating move m by finding score public static int chooseMove3Ply(Board b, char ox) for (int m=0 ; m<b.getCols() ; ++m) { if (b.allowsMove(m)) Board b2 = b.newAddMove(m,ox); if ( b2.winsFor(ox) || b2.isFull() ) score = evaluate(b,ox); else int m2 = chooseMove2Ply(b2,opp(ox)); Board b3 = b2.newAddMove(m2,opp(ox)); if ( b3.winsFor(opp(ox)) || b3.isFull() ) int m3 = chooseMove1Ply(b3,ox); Board b4 = b3.newAddMove(m3, ox); score = evaluate(b4, ox); } if (score > BSSF) BSSF = score; BMSF = m; } // end if (b.allowsMove(m)) } // end for (int m=0 ; … return BMSF; Ex. Cr. evaluating move m by finding score remembering the best score and the best move m so far

int chooseMove(Board b, char ox, int ply) Looking N Ply ahead! 1-ply search 2-ply search 3-ply search N-ply search chooseMove1Ply chooseMove2Ply chooseMove3Ply evaluate (N-1) - ply ... 1 - ply 2 - ply int chooseMove(Board b, char ox, int ply) With a 4-ply lookahead, X will think every move looks equivalent on this board With a 5-ply lookahead, X will know to move to column 3 ‘X’ ‘O’ 1 2 3 4 5 6