COMP 110: Introduction to Programming Tyler Johnson Apr 1, 2009 MWF 11:00AM-12:15PM Sitterson 014.

Slides:



Advertisements
Similar presentations
101 Will tweet for work! How to get twitter to work for you Daulton West and Scott Gravitt June 30, 2009.
Advertisements

COMP 110: Introduction to Programming Tyler Johnson Feb 11, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 18, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 20, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 13, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 26, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 12, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 8, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 28, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming
COMP 110: Introduction to Programming Tyler Johnson Mar 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 4, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Covert Barcodes handle on-the-spot Brand and Document Authentication Information Management Institute Conference on Security Printing 11/18/2009 Read what.
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
2010 Tax Class1 Day 3 Class Participation Class Exercise – Paul Austin Publ W Exercise page 98 Advanced Section.
Tax Year Site Procedures, Quality Reviews, In-Scope.
Tax Year TYPES OF PAYMENTS 1040 PG 2 Line & 68 Federal income tax withheld from W-2s, 1099s Estimated payments & $ applied from prior year.
Large Scale Integration of Senses for the Semantic Web Jorge Gracia, Mathieu dAquin, Eduardo Mena Computer Science and Systems Engineering Department (DIIS)
Producing monthly estimates of labour market indicators exploiting the longitudinal dimension of the LFS microdata R. Gatto, S. Loriga, A. Spizzichino.
Wouter Noordkamp The assessment of new platforms on operational performance and manning concepts.
Chapter 7: Arrays In this chapter, you will learn about
Privately Querying Location-based Services with SybilQuery Pravin Shankar, Vinod Ganapathy, and Liviu Iftode Department of Computer Science Rutgers University.
Quality Management for the Medical Laboratory
Student Learning Center Time Management Welcome to the Time Management workshop. While we are waiting to begin, please fill out the blank weekly.
Wrap up of the thermal and thermo mechanical simulation on the IBL stave Simone Coelli Mauro Monti INFN Milano ATLAS PIXEL Inserted B-Layer Eng. Meeting.
Ziehm Academy - User Guide for online registration portal Nuremberg, February 2009.
1 Arrays … The Sequel Applications and Extensions Chapter 10.
Clarity Chromatography Software
Automation Solutions for Ladle Gate Applications
1 Cathay Life Insurance Ltd. (Vietnam) 27/11/20091.
Presented by: Yaseen Ali, Suraj Bhardwaj, Rohan Shah Yaseen Ali, Suraj Bhardwaj, Rohan Shah Mechatronics Engineering Group 302 Instructor: Dr. K. Sartipi.
ATUG Roundtable – November 2009 NBN Architecture Reference Model.
IV Medicine Administration: Infection Control September 2009.
Arrays.
IG Pro & CMS.
Vault 9 Project Update 9 th September 2009 Paul Pointon – Site Project Delivery Manager LLW Repository Ltd.
30 min Scratch July min intro to Scratch A Quick-and-Dirty approach Leaving lots of exploration for the future. (5 hour lesson plan available)
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Flexible Scheduling of Software with Logical Execution Time Constraints* Stefan Resmerita and Patricia Derler University of Salzburg, Austria *UC Berkeley,
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.
Arrays. INTRODUCTION TO ARRAYS Just as with loops and conditions, arrays are a common programming construct and an important concept Arrays can be found.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
Chapter 7 – Arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
COMP 14 Introduction to Programming Mr. Joshua Stough February 16, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
COS 260 DAY 16 Tony Gauvin.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
COMP More About Arrays Yi Hong June 05, 2015.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
COMP 110 More arrays, 2D arrays, Program 4 Luv Kohli November 10, 2008 MWF 2-2:50 pm Sitterson 014.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
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.
COMP 110 More arrays, 2D arrays, Program 4
Chapter 8 – Arrays and Array Lists
Multi-dimensional Array
Chapter 7 Part 2 Edited by JJ Shepherd
Presentation transcript:

COMP 110: Introduction to Programming Tyler Johnson Apr 1, 2009 MWF 11:00AM-12:15PM Sitterson 014

COMP 110: Spring Announcements Lab 6 has been graded

COMP 110: Spring Questions?

COMP 110: Spring Today in COMP 110 Some Misc. Items Multi-Dimensional Arrays Programming Demo TicTacToe

COMP 110: Spring Program 4 Some comments

COMP 110: Spring Program 4 Extended to Friday at 5pm to better match the other section

COMP 110: Spring Lab 7 Some comments on the reverse/wheel methods

COMP 110: Spring Lab 6

COMP 110: Spring Multi-Dimensional Arrays Section 7.5 in text

COMP 110: Spring D Arrays Arrays having more than one index are often useful Tables Grids Bingo games 0: Open1: High2: Low3: Close 0: Apple Inc : Walt Disney Co : Google Inc : Microsoft Corp

COMP 110: Spring Creating 2D Arrays //create a 2D array with 4 rows and 3 columns int[][] table = new int[4][3]; or int[][] table; table = new int[4][3]; rows columns Can be used to create a table that looks like this

COMP 110: Spring Creating 2D Arrays int[][] table = new int[4][3]; gives you access to table[0][0] //1 st row, 1 st column table[0][1] //1 st row, 2 nd column table[0][2] //1 st row, 3 rd column table[1][0] table[1][1] table[1][2] table[2][0] table[2][1] table[2][2] table[3][0] //4 th row, 1 st column table[3][1] //4 th row, 2 nd column table[3][2] //4 th row, 3 rd column table[0][0]table[0][1]table[0][2] table[1][0]table[1][1]table[1][2] table[2][0]table[2][1]table[2][2] table[3][0]table[3][1]table[3][2]

COMP 110: Spring Using 1D Arrays We used a single loop to process a 1D array int[] scores = { 13, 57, 93, 60, 102 }; for(int i = 0; i < scores.length; i++) { System.out.println(scores[i]); }

COMP 110: Spring Using 2D Arrays When processing 2D arrays, we usually used two nested loops int[][] table = new int[4][3]; //the outer loop iterates over the rows for(int row = 0; row < 4; row++) { //the inner loop iterates over the columns for(int column = 0; column < 3; column++) { table[row][column] = 0; }

COMP 110: Spring Multi-Dimensional Arrays You can have more than two dimensions int[][][] table = new int[4][3][5]; Use more nested loops to access all elements

COMP 110: Spring Representation of 2D Arrays int[] scores = new int[5]; scores is a one-dimensional array The type of scores[0], scores[1] etc is int int[][] table = new int[4][3]; Internally table is also represented as a one- dimensional array The type of table[0], table[1] etc is int[] (an array!) We still refer to table as a two-dimensional array

COMP 110: Spring Representation of 2D Arrays int[][] table = new int[4][3]; table[0] table[1] table[2] table[3] table 579

COMP 110: Spring Length field for 2D Arrays int[][] table = new int[4][3]; table.length gives the number of rows (4 in this case) table[0].length, table[1].length etc gives the number of columns (3 in this case)

COMP 110: Spring Multi-Dimensional Arrays as Parameters //a method to print a 2D array to screen public void print2DArray(int[][] arr) { for(int row = 0; row < arr.length; row++) { for(int column = 0; column < arr[row].length; column++) { System.out.print(arr[row][column] + " "); } System.out.println(); //jump to the next line after each row is complete }

COMP 110: Spring Multi-Dimensional Arrays as Return Types //create a 2D array of the specified size and return it public int[][] create2DArray(int rows, int columns) { int[][] array = new int[rows][columns]; return array; }

COMP 110: Spring Programming Demo TicTacToe Create a class that allows the user to play a game of TicTacToe

COMP 110: Spring TicTacToe Represent the game board as a 2D array of size 3x3 Type? char XOO OXX XXO

COMP 110: Spring Pseudocode Until done display game board display game menu (move, restart, quit) if(move) ask where to move, update game board if(winner || board full) –done = true else if(restart) reset the game else if(quit) exit

COMP 110: Spring Decomposition Public methods Constructor sets everything up void play() starts the game Private Methods void displayBoard() Displays the entire game board void displayRow(int row) Displays a single row of the game board Used by displayBoard() void displayMenu() Displays the options menu to the user boolean getMove() Allows the user to update the game board by making a move Returns true if the move resulted in a winner and false if not boolean winner(int lastR, int lastC) Checks if the move to lastR,lastC resulted in a winner Used by getMove() boolean boardFull() Returns whether the board is full and the game is over

COMP 110: Spring Programming Demo Programming

COMP 110: Spring Friday Recitation Bring Laptop (fully charged) Textbook