Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Introduction to Programming Lecture 39. Copy Constructor.
CS12230 Introduction to Programming Tying things together.
EECS 110: Lec 14: Classes and Objects Aleksandar Kuzmanovic Northwestern University
"Intelligent" CS 5 An object is structured data that is alive, responsible, and intelligent. Sound too friendly? This week’s objects and classes will be.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. It is common to use two nested loops when filling or searching: for.
Stacks CS 3358 – Data Structures. What is a stack? It is an ordered group of homogeneous items of elements. Elements are added to and removed from the.
Helper Methods ITP © Ron Poet Lecture 11.
Homework 6 Due ( MT sections ) ( WTh sections ) about midnight Sun., 10/12 Mon., 10/13 Problems
Two examples of Problem Solving in Programming H. Chad Lane University of Pittsburgh CS7: Introduction to Programming.
HW 6: Problems 2&3 Simulating Connect 4.
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
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
1 Tirgul no. 3 Topics covered: H Iteration. H Defining and using classes.
Homework 4 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/29 Mon., 9/30 Problems
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/30/2012 and 10/31/2012 -Code PrintCalendar.
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.
A whole new class of programming CS 5 today HW10: Due Sun, Nov 15 Pr0: Ariane 5 Reading Pr1/Lab:the Date class Pr2 Connect4Board Pr3 Connect4Player (extra.
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 Classes Using Java Classes Introduction to UML.
IS 313 Today Schedule Week 0: Classes Objects You're saying that Python's got class ? Dictionaries and Classes Week 1: Week 2: Where.
Def tomorrow(self): """Changes the calling object so that it represents one calendar day after the date it originally represented. """ if self.month in.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/23/2012 and 10/24/2012 -Using Exceptions -Homework 4.
CSE 143 Lecture 17 More Recursive Backtracking reading: "Appendix R" on course web site slides created by Marty Stepp and Hélène Martin
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
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Midterm 2 Review 1. 2 Object Oriented Programming Write a Date class. It should contain fields for day, month, year, number of months per year, and number.
HW 6: Problems 2 & 3 Simulating Connect 4. HW 6: Overview Connect 4: Variation of Tic-Tac-Toe – Board: Vertical 7x6 – Two players take alternating move.
Objects & Classes Weiss ch. 3. So far: –Point (see java.awt.Point) –String –Arrays of various kinds –IPAddress (see java.net.InetAddress) The Java API.
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.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
Homework #2: Functions and Arrays By J. H. Wang Mar. 24, 2014.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Code Compression the benefits of looping... Today in CS 5 HW 4 - (3 problems) M/T sections W/Th sections due Sunday, 9/26 at midnight due Monday, 9/27.
CSE 143 Lecture 18 More Recursive Backtracking slides created by Marty Stepp
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
1 Enums (Chapter 4) To enumerate is: to name things one after another in a list Java has a type, called an enum, where a programmer specifies a finite.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Nelson Series Talk Wed, 10/13 7:00 pm HMC’s Galileo Auditorium On Robots, Probability, and Artificial Intelligence This talk will expose the audience.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
IS313 Tomorrow… Wednesday, Nov Classes + Objects, part 2 Wednesday, Nov Classes + Objects, part 3 Thursday, Nov Date class due Thursday,
A 2-D Array is a structure that storage space both vertically and horizontally. Thus, the array has both rows and columns. 2-D Arrays are used to create.
COMPUTER 2430 Object Oriented Programming and Data Structures I
EECS 110: Lec 15: Classes and Objects (2)
Homework 12 Sun., 11/24 Due Mon., 11/25 Problems (2 of them)
Chapter 7 User-Defined Methods.
using System; namespace Demo01 { class Program
CS305J Introduction to Computing
Computer Programming Methodology Input and While Loop
CSC 113 Tutorial QUIZ I.

Truth tables: Ways to organize results of Boolean expressions.
CSE 143 Lecture 18 More Recursive Backtracking
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSE 143 Lecture 18 More Recursive Backtracking
EECS 110: Lec 15: Classes and Objects (2)
Computer Science Club 1st November 2019.
Presentation transcript:

Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems Tutors available Fri., Sat. afternoons Lac Lab and Parsons (1-4) Sunday afternoons Lac Lab and Parsons (1-4) Sunday evenings Lac Lab and Parsons (7-12) Monday evenings Lac Lab and Parsons (7-12) names and hours linked from the CS 5 Syllabus

Problem 2: Connect Four | | | | | | | |X|O| | | | |X| |X|O| | | |X|O|O|O|X| | | An object of the Board class... underlying data: a 2d array of char s the user chooses the number of rows and columns (between 4 and 15 inclusive) each player is a char -- either ‘X’ or ‘O’

Problem 2: CS5App class class CS5App { public static void main(String[] s) { int rows = H.in.nextInt(); int cols = H.in.nextInt(); Board b = new Board(rows,cols); while (playing) { b.print(); // print out the board // get a move from ‘X’ // add it to the board // see if ‘X’ wins or b is full // do the same for ‘O’ } The constructor for objects of type Board

The Board class | | | | | | | |X|O| | | | |X| |X|O| | | |X|O|O|O|X| | | Board b char[] char[][] data char char[]char int nRows int nCols void print() boolean isFull() boolean allowsMove(int c) void addMove(int c, char player) boolean winsFor(char player) b.print()

The Board class class Board { private char[][] data; // private data members private int nRows; private int nCols; Board(int rows, int cols) // CONSTRUCTOR ! { this.nRows = rows; this.nCols = cols; this.data = new char[rows][cols]; for (int r=0 ; r<this.nRows ; ++r) for (int c=0 ; c<this.nCols ; ++c) this.data[r][c] = }

print class Board { public void print() { | | | | | | | |X|O| | | | |X| |X|O| | | |X|O|O|O|X| | | this.data is the array of pieces or spaces other code here… this.nRows is the # rows this.nCols is the # cols

allowsMove class Board { // previous Board code … public boolean allowsMove(int col) { | | | | |X| | | | | | |X|O| | | | | | |O|X| | | | | | |X|O| | | | |X| |X|O| | | |X|O|O|O|X| | |

addMove class Board { // previous Board code … public void addMove(int col, char player) { | | | | | | | |X|O| | | | |X| |X|O| | | |X|O|O|O|X| | |

winsFor class Board { // previous Board code … public boolean winsFor(char player) { | | | | | | |O|X|O| | | |X|X|X|X|O| | | |X|O|O|O|X|O| |

Problem 2: main loop Board b = new Board(rows,cols); while (playing) { b.print(); // print out the board // get a move from ‘X’ // add it to the board // check win or tie… // repeat for ‘O’

Problem 1 Similar to the last two problem 1’s, 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 Date s returns a String Methods

if (choice==0) { // input mo, dy, yr again d = new Date(mo,day,yr) } Problem 1 (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 sets things up and runs a large while loop // input integers: mo,dy,yr Date d = new Date(mo,dy,yr); while (choice != 9) { d.print(); printMenu(); printMenu prints Methods Date Calculator if (choice==2) { d.tomorrow() } …

The Date class class Date { private int month; private int day; private int year; public Date(int mo, int dy, int yr) { this.month = mo; this.day = dy; this.year = yr; } public void print() { H.out.print(this.month + “/” + this.day + “/” + this.year); } data members other method(s) constructor initializes all of the data members used whenever a new object is created

tomorrow() class Date { // previous Date code … public void tomorrow() { this.day++; // add one to the day // check if we overflowed the month! if (this.day == 32 && this.month == 12) { this.day = 1; this.month = 1; this.year++; } else if (this.day == 28 && this.month == 2 && !this.isLeapYear() ) { this.month = 3; this.day = 1; } else if ( /* lots of other cases … */ ) } int day int year int month data members

Comparing Date s class CS5App { public static void main(String[] args) { Date d = new Date(11,8,2002); // today Date d2 = new Date(11,28,2002); // Thanksgiving int nDays = d.diff(d2); H.out.print(“Between ”); d.print(); H.out.print(“ and ”); d2.print(); H.out.println(“ there are ” + nDays + “days.”); }

diff class Date { // previous Date code … public int diff(Date d2) { } What two dates are being compared here?

dayOfWeek class Date { // previous Date code … public String dayOfWeek() { }

Picture of a Date object Date int month int day int year Date d void print() void tomorrow()