COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke.

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

Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
– Advanced Programming P ROGRAMMING IN Lecture 16 Interfaces.
CS 307 Fundamentals of Computer Science 1 Linked Lists many slides taken from Mike Scott, UT Austin.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
COMP 114 Weekly Recitation November 14, 2003 What’s Happening Monday? Second exam The Second exam !
COMP 114 Kimberly Noonan (040) Chris Vanderknyff (040) William Luebke (039)
COMP 114 Recitation Kimberly Noonan Chris VanderKnyff William Luebke.
Generics OOP Tirgul What is it good for ? Stack myStack = new Stack() ; // old version (1.4.2) myStack.push(new Integer(0)) ; int x = ((Integer)
COMP 114 Kimberly Noonan Chris VanderKnyff William Luebke.
MAHARISHI INTERNATIONAL UNIVERSITY M AHARISHI U NIVERSITY of M ANAGEMENT Engaging the Managing Intelligence of Nature.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Programming Progamz pls. Importance VERY IMPORTANT.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
1 Linear and Binary Search Instructor: Mainak Chaudhuri
Arrays of Objects 1 Fall 2012 CS2302: Programming Principles.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
LinkedList Many slides from Horstmann modified by Dr V.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
Consider the following Which of the following will cause a java.lang.ClassCastException? a)Alpha a = x; b)Foo f= (Delta)x; c)Foo f= (Alpha)x; d)Beta b.
Recitation 2 James Wei Professor Peck 1/17/2013. Covered in this Recitation Arrays Variable Scoping Local variables Instance variables Class variables.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
CSE 143 Lecture 10 Linked List Basics reading: slides created by Marty Stepp
Object-Oriented Programming Simple Stack Implementation.
COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke.
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.
CS 2430 Day 12. Agenda for today Container class example: DateList Growable container classes.
Testing with JUnit, and ArraySet costs 2014-T2 Lecture 11 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean,
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
1. Last Lecture Stacks and Queues implemented with a Linked List Doubly Linked Lists 2 Today.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Object-Oriented Programming Dr. Ramzi Saifan Slides adapted from Prof. Steven Roehrig.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Marcus Frean.
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
Iterator Summary Slides by Entesar Al-Mosallam adopted from Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
CS 46B: Introduction to Data Structures July 23 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
Java Collection Classes Com379PT
slides adapted from Marty Stepp and Hélène Martin
Lecture 11 Instructor: Craig Duckett Instance Variables.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
using System; namespace Demo01 { class Program
Interface.
Interfaces and an Array List
Functions Used to write code only once Can use parameters.
Computing Adjusted Quiz Total Score
TO COMPLETE THE FOLLOWING:
COMPUTER 2430 Object Oriented Programming and Data Structures I
CNT 4007C Project 2 Good morning, everyone. In this class, we will have a brief look at the project 2. Project 2 is basically the same with project 1.
slides created by Alyssa Harding
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Code Animation Examples
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
COMPUTER 2430 Object Oriented Programming and Data Structures I
Scope of variables class scopeofvars {
Review of Previous Lesson
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Lecture 22: Number Systems
Presentation transcript:

COMP 114 Chris VanderKnyff Kimberly Noonan William Luebke

What we’re going to do today… Questions from Monday’s and Wednesday’s Lecture Questions from Monday’s and Wednesday’s Lecture Example using Interfaces Example using Interfaces

Growable Array Want to be able to add Objects to the array without having to worry about if the array is large enough. Want to be able to add Objects to the array without having to worry about if the array is large enough. Want to be able to retrieve Objects out of the array. Want to be able to retrieve Objects out of the array. Want to be able to determine the number of objects we’ve added to the array. Want to be able to determine the number of objects we’ve added to the array.

Growable Array Interface public interface GrowableArray { // (?) Do you need a public here? public void add(Object o); public Object get(int i); public Object get(int i); public int size(); }

Implementation 1: Duke public class DukeProgramThatUsesArrays { public static void main(String args[]) { GrowableArray array=new DukeGrowableArray(); final int SOME_MODERATELY_SIZED_NUMBER=1000; for (int i=0;i<SOME_MODERATELY_SIZED_NUMBER;i++) { System.out.println("About to add "+i+ " to the array..."); array.add(Integer.toString(i)); System.out.println(i+" successfully “+ “added... array size is now: “+ array.size()+"."); } };

What Happened?

DukeGrowableArray public class DukeGrowableArray implements GrowableArray { private static final int MAX_SIZE=100; // (?) Why static? // (?) What's with the _'s? private Object _array[]=new Object[MAX_SIZE]; private int _size=0; public DukeGrowableArray() { } public int size() { return _size; } public Object get(int i) { return _array[i]; } public void add(Object o) { _array[_size++]=o; // (?) Order of operations! }

Implementation 2: UNC (Part 1) public class UNCGrowableArray implements GrowableArray { private static final int DEFAULT_INITIAL_SIZE=4; private Object _array[]; private int _size=0; public UNCGrowableArray() { // (?) What does the "this" do? this(DEFAULT_INITIAL_SIZE); } // (?) Why would this be useful? public UNCGrowableArray(int initialSize) { _array=new Object[initialSize]; } // MORE ON NEXT SLIDE...

Implementation 2: UNC (Part 2) public int size() { return _size; } public Object get(int i) { return _array[i]; } public void add(Object o) { if (_size==_array.length) { Object array[]=new Object[_size<<1]; // (?) Why << ? for (int i=0;i<_array.length;i++) { array[i]=_array[i]; } _array=array; } _array[_size++]=o; }

Implementation 2: UNC public class UNCProgramThatUsesArrays { public static void main(String args[]) { //GrowableArray array=new DukeGrowableArray(); GrowableArray array=new UNCGrowableArray(); final int SOME_MODERATELY_SIZED_NUMBER=1000; for (int i=0;i<SOME_MODERATELY_SIZED_NUMBER;i++) { System.out.println("About to add "+i+ " to the array..."); array.add(Integer.toString(i)); System.out.println(i+" successfully “+ “added... array size is now: “+ array.size()+"."); } };

Behold!