Discussion 7. Make up tutorial Official make up slot: Friday 27 Oct (4-6) (by majority of the people that send me the email) For those who cannot make.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

Arrays.
Introduction to arrays
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Week 6: Arrays 1.  Loops are great  But, without a way to talk about a group of values, we can’t get the full potential out of a loop  Enter: the array.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Building Java Programs Chapter 7.5
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Building Java Programs Chapter 13 Searching reading: 13.3.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Arrays. Arrays in Java  Arrays in Java are objects.  Like all objects are created with the new keyword.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Java Programming: From Problem Analysis to Program Design, 4e
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Chapter 6- Arrays. Overview n What are arrays? n Declaring/initializing arrays. n Using arrays. n Arrays details. n Using arrays with classes/ in classes.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Arrays, ArrayLists, and Collections. Rationale Suppose we have a program to compute the average of three numbers. We could write a simple little method.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
OBJECTS FOR ORGANIZING DATA -- As our programs get more sophisticated, we need assistance organizing large amounts of data. : array declaration and use.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
ITI 1120 Lab #9 Slides by: Diana Inkpen and Alan Williams.
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.
CS1101: Programming Methodology
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
The "8 Queens" problem Consider the problem of trying to place 8 queens on a chess board such that no queen can attack another queen. What are the "choices"?
CS 100Lecture 191 CS100J Lecture 19 n Previous Lecture –Two dimensional arrays. –Reasonable size problem (a past assignment). –Stepwise refinement. –Use.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays days until the AP Computer Science test.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Two Dimensional Arrays. Students will be able to: code algorithms to solve two- dimensional array problems. use 2-D arrays in programs. pass two-use 2-D.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Writing a GamesCrafters Game in C Monday, Sept. 22, 2003 Judy Chen.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
ARRAYS Multidimensional realities Image courtesy of
CS 221 – May 23 Sorting in parallel (section 3.7) Special algorithm: parallel version of bubble sort. Lab: – Please implement a serial version of this.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Beginning C for Engineers Fall 2005 Arrays, 2-D arrays, character strings Bettina Schimanski Lecture 5: Section 2 (9/28/05) Section 4 (9/29/05)
APS105 Malloc and 2D Arrays (text Ch6.4, Ch10.2).
Recursion – some examples. Sum of Squares Write Vertical.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Lecture 18: Nested Loops and Two-Dimensional Arrays
Lecture 5 of Computer Science II
Intro to Computer Science II
Arrays 1. One dimensional arrays - Review 2. Using arrays
multi-dimensional arrays
Sit-In Lab 1 Ob-CHESS-ion
Announcements & review
Tic Tac Toe application
Peer Instruction 4 Control Loops.
2-Dimensional Lists (Matrices) in Python
Two dimensional arrays.
Two dimensional arrays.
Presentation transcript:

Discussion 7

Make up tutorial Official make up slot: Friday 27 Oct (4-6) (by majority of the people that send me the ) For those who cannot make it, please let me know the me on the time slots you might to see me (optional) Monday 23 Oct (6pm) Thursday 22 Oct (4-6pm) Friday 27 Oct (2-4pm)

Questions on labs? Nice Ebook on Java Regex esV1.pdf esV1.pdf

Arrays? 1D arrays? 2D arrays? ArrayList

Lab4 // Returns the number of hits between object and guessPegs public int countHits (FourPegs guessPegs) { int count = 0; boolean[] used = new boolean[4]; for (int i = 1 ; i <= 4 ; i++){ if (guessPegs.getColour(i) == getColour(i)) used[i-1] = true; } for (int i = 1 ; i <= 4 ; i++){ for (int j = 1 ;j <= 4 ; j++){ if (i != j && guessPegs.getColour(i) == getColour(j) && !used[j-1]){ count++; used[j-1] = true; } return count; }

Question 1 pg Identify problems with this code: public int searchAccount( int[25] number ) { number = new int[15]; for (int i = 0; i < number.length; i++ ) number[i] = number[i-1] + number[i+1]; return number; }

Question 1 pg Identify problems with this code: public int searchAccount( int[25] number ) {  1 number = new int[15]; for (int i = 0; i < number.length; i++ )  2 number[i] = number[i-1] + number[i+1]; return number;  3 } 1. Parameter declaration cannot include size (25) information. 2. The for loop will cause an ArrayIndexOutOfBounds exception when i = 0 because it will access number[i – 1] which will be number[-1] and is out of bounds because you can ’ t have a negative array index. 3. The return value number is not of type int it is int[].

Question 3.What is wrong with the following algorithm that transposes an m  m square matrix? Transposing a matrix means exchanging the rows with the respective columns, that is, matrix[row][col]  matrix[col][row]. Below shows the result of transposing a 3  3 matrix. Before transpose:2 4 5After transpose: for (int row = 0; row < m; ++row) { for (int col = 0; col < m; ++col) { // swap matrix[row][col] with matrix[col][row] }

Question (Cont.) 3.What is wrong with the following algorithm that transposes an m  m square matrix? Transposing a matrix means exchanging the rows with the respective columns, that is, matrix[row][col]  matrix[col][row]. Below shows the result of transposing a 3  3 matrix. Before transpose:2 4 5After transpose: for (int row = 0; row < m; ++row) { for (int col = 0; col < m; ++col) { // swap matrix[row][col] with matrix[col][row] } Can you come up with a solution( with a display method)? Another solution? Anymore solutions?! Which 1 is the best solution?

Tic Tac Toe Download main program from /cs1101/TicTacToe.java /cs1101/Board.java /cs1101/TicTacToe.java /cs1101/Board.java We are going to implement the Board class which is to be used for TicTacToe