Week 91 Introduction to Programming Ms. Knudtzon C Period Quarter 2 – Lecture 20 Monday, November 1 st.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Chapter 8: Arrays.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
18-Jun-15 Arrays. 2 A problem with simple variables One variable holds one value The value may change over time, but at any given time, a variable holds.
Introduction to Computers and Programming Lecture 15: Arrays Professor: Evan Korth New York University.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS100J 17 March 2005 Arrays. Reading: Secs 8.1, 8.2, 8.3. The last Java feature to study in this course Quote for the Day: Computer science has its field.
Chapter 5 - Arrays CSC 200 Matt Kayala 2/27/06. Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Introduction to a Programming Environment
Wednesday, 11/6/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/6/02  QUESTIONS?? – HW # 4 due Monday  Today:  Return HW #3  Arrays (Chap. 10)  Reading:
1 CS100J 25 October 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
 Pearson Education, Inc. All rights reserved Arrays.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
CSE 332: C++ program structure and development environment C++ Program Structure (and tools) Today we’ll talk generally about C++ development (plus a few.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Week101 APCS-A: Java November 8, week102 Java Packages All Java classes are grouped into libraries (or packages)  String is part of the java.lang.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
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.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
ARRAYS 1 TOPIC 8 l Array Basics l Arrays and Methods l Programming with Arrays Arrays.
1 BUILDING JAVA PROGRAMS CHAPTER 7.1 ARRAY BASICS.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Week91 APCS-AB: Java Problem Solving November 1, 2005.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
1 On (computational) simplicity We are trying to teach not just Java, but how to think about problem solving. Computer science has its field called computational.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
Working With Objects Tonga Institute of Higher Education.
Slide 1 Chapter 5 Arrays. Slide 2 Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays  Arrays in memory.
Chapter 5 Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Learning Objectives  Introduction to Arrays  Declaring and referencing.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Grouping objects Arrays. 2 Fixed-size collections The maximum collection size may be pre-determined with an upper limit Array is an fixed-size collection.
Written by: Dr. JJ Shepherd
BIT115: Introduction to Programming
Data Structures Arrays and Lists Part 2 More List Operations.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Introduction to programming in java Lecture 23 Two dimensional (2D) Arrays – Part 3.
Introduction to programming in java Lecture 21 Arrays – Part 1.
13 Arrays CE : Fundamental Programming Techniques June 161.
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)
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Chapter VII: Arrays.
Chapter 7 Part 1 Edited by JJ Shepherd
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
EKT150 : Computer Programming
MSIS 655 Advanced Business Applications Programming
Arrays in Java.
Classes, Objects and Methods
Corresponds with Chapter 5
Presentation transcript:

Week 91 Introduction to Programming Ms. Knudtzon C Period Quarter 2 – Lecture 20 Monday, November 1 st

Week 92 Debugging and Testing What is debugging? What is testing?

Week 93 Testing Is used to find out whether a piece of code (a method, class, or entire program) produces the intended behavior Testing well is not easy because there is a lot to think about when testing a program Unit testing refers to a test of individual parts of an application (can be done before an application is complete)

Week 94 Debugging Debugging generally comes after testing Is the attempt to pinpoint and fix the source of an error

Week 95 Debugger A debugger is a software tool that helps in examining how an application executes. It can be used to find bugs. –Lets you execute an application one step at a time –Lets you start and stop a program at selected points in the source code, and to examine the value of variables

Week 96 Why is an error called a BUG? ‘The first computer bug’ – was found inside the Mark II computer by Grace Murray Hopper in 1945 –(Can be seen at the National Museum of American History)

Week 97 Debuggers Can vary in complexity Those for professional developers are much more complex than the simple version we will use in BlueJ BlueJ’s debugger is good for novice programmers, and can give a lot of information that can be useful in understanding how the program works

Week 98 The this keyword Used for name overloading – the same name is used for two different entities –this can be used in methods or in constructors Example: (From the Car.java program) String make; public void setMake(String make){ this.make = make; } Note: the parameter (make) and the class variable or field (make) share the same name, but are two different containers Java specification says that the definition from the closest enclosing block {} will always be used The this keyword refers to the current object – so this.make refers to the class variable make, not the parameter make Used to make the code more readable

Week 99 In class Lab (Teams of 2) \\bonebox\users\Knudtzon\Java\mail-system –Exercise 3.31 –Exercise 3.33 –Exercise 3.34 – Then follow directions and exercises on pages –Time permitting: Add a subject line for an to MailItem s in the mail-system project. Make sure printing messages also prints the subject line. Modify the mail client accordingly. (Exercise 3.43)

Week 910 Introduction to Programming Ms. Knudtzon C Period Quarter 2 – Lecture 21 Thursday, November 4 th

Week 911 Schedule (Went over asterisks program from homework 9) Will come back to testing in more detail later this quarter, for now it suffices to test by calling individual methods through the BlueJ object bench Was going to begin covering Java API, but since there is no school tomorrow, will first cover arrays

Week 912 Grouping objects Fixed-sized collections –When you know in advance how many items will be stored in a collection (and that stays fixed for the life of the collection) –A fixed-sized collection is an array It’s kind of like a tray of cups – each cup can hold an object or a primitive data type Note: the array itself is an object Flexible-sized collections –When you don’t know in advance how many items you will need to store –Will go into more details about this when we look at the Java API

Week 913 Arrays An array is a group of variables (called elements or components) containing values that all have the same data type To refer to a particular element in an array, use the array’s name and the position number of the element in the array int array called c c[0] c[3] c[4] c[5] c[6] c[7] c[8] c[1] c[2]

Week 914 Anatomy of an array Array names are the same as any other variable name An array with 9 elements (or variables) First element has index zero (the zeroth element) ith element of array c is c[i -1] Index must be a positive integer (or an integer expression that can be promoted to an int) int array called c c[0] c[3] c[4] c[5] c[6] c[7] c[8] c[1] c[2]

Week 915 Advantages to using arrays It is easy to access individual items in an array (and it’s efficient) Arrays are able to store objects or primitive type values (int, double, float, etc) –(We’ll see later that the flexible-sized collections can only store objects)

Week 916 Declaring and creating arrays Array objects occupy space in memory. All objects in Java must be created with a keyword new When you declare an array you must tell Java the type of the array elements and the number of the elements that will appear in the array Example declaration for an integer array called hourArray: int hourArray[] = new int[24]; // declares and creates an array to hold 24 int elements

Week 917 An array hourArray :int[ ]

Week 918 Other kinds of arrays How would you create an array to hold 20 student names? int jesseArray[] = new int[20]; String nameArray[] = new String[20];

Week 919 How do we fill an array? All values are initially set to zero when we initialize an array One way to fill the array is to use an array initializer, a comma-separated list of expression enclosed in braces: int n[] = {10, 23, 34, 235, 234}; –The array length is automatically determined by the number of elements in the initializer list

Week 920 Class Exercise Write code to declare and initialize an array to hold the months of a year String month[] = {“jan”, “feb”, “march”, “april”, “may”}; Write code to declare and initialize an array to hold the number of days in each month of the year int monthDays[] = {31,28,31,30};

Week 921 How else do we fill an array? Arrays and for-loops go together like peanut butter and jelly! We could use a for loop and access each array element to set a value to it: int myArray[] = new int[10]; for(int i =0; i < myArray.length; i++){ myArray[i] = 5 * i; }

Week 922 Exercise Suppose we wish to print out the names and lengths of each of the months To do this for each of the twelve months, we place this statement in the body of a for loop that counts off all the months String monthNames[] = {"January","February","March","April", "May","June","July","August", "September","October","November","December"}; int monthDays[] = {31,28,31,30,31,30,31,31,30,31,30,31}; for(int j = 0; j < 12; j++){ System.out.println(“Month: “ + monthNames[j] + “ has “ + monthDays[j] + “ days”); }

Week 923 Histogram Program ArrayEx

Week 924 Mistakes It is not uncommon to make a programming mistake that causes the bounds of a loop to be mis-defined and the loop index variable to stray beyond the range of the array. For example, what if in your for loop you wrote: for(int i = 0; i <= array.length; i++){ System.out.println(array[i]); }

Week 925 Homework 10 Will be posted today on the webpage Due date to be determined (Probably November 12) –Get started this weekend!