COMP-202: Foundations of Programming. Lecture 11: ArrayList, and Linked List Sandeep Manjanna, Summer 2015
|
|
- Mae Aubrey Woods
- 5 years ago
- Views:
Transcription
1 COMP-202: Foundations of Programming Lecture 11: ArrayList, and Linked List Sandeep Manjanna, Summer 2015
2 Announcements Assignment 4 will be posted by the end of day today. Course Evaluations are now open. Direct feedback on my course and my teaching. Minerva Student menu t_code=f Final exams : 26 th of June (2pm to MAASS 112
3 This Lecture Review on classes and objects ArrayList Linked List One step at a time.
4 Review: Classes and Objects
5 public class Dog{ private double height; private double age; private static int numdogs = 0; public Dog (double h, double a){ height = h; age = a; numdogs++; System.out.println("The dog's height is "+height+", and age is "+age); public Dog (double a){ age = a; height = 0.5; numdogs++; System.out.println("The dog's age is "+age); public static void main(string[] str){ Dog d1,d2;
6 public class Dog{ private double height; private double age; private static int numdogs = 0; public Dog (double h, double a){ height = h; age = a; numdogs++; System.out.println("The dog's height is "+height+", and age is "+age); public Dog (double a){ age = a; height = 0.5; numdogs++; System.out.println("The dog's age is "+age); public static void main(string[] str){ Dog d1,d2; d1 = new Dog(1.5); d2 = new Dog(1.5, 1);
7 public class Dog{ private double height; private double age; public Dog (double h, double a){ height = h; age = a; public Dog (double a){ age = a; height = 0.5; public boolean equals(dog d){ if((height == d.height) && (age == d.age)) return true; return false; public static void main(string[] str){ Dog d1 = new Dog(1.5); Dog d2 = new Dog(1.5, 1); System.out.println("The two dogs are equal : "+d2.equals(d1));
8 public class Dog{ private double height; private double age; public Dog (double h, double a){ height = h; age = a; public Dog (double a){ age = a; height = 0.5; public boolean equals(dog d){ if((height == d.height) && (age == d.age)) return true; return false; public static void main(string[] str){ Dog d1 = new Dog(1.5); Dog d2 = new Dog(0.5, 1.5); System.out.println("The two dogs are equal : "+d2.equals(d1));
9 public class testdog{ public static void main(string[] str) { Dog d1 = new Dog(1); Dog d2 = new Dog(1.5, 2); swap(d1,d2); System.out.println("d1's age = "+d1.age); public static void swap(dog dog1, Dog dog2) { Dog temp = dog1; dog1 = dog2; dog2 = temp; public class Dog{ public double height; public double age; public Dog (double h, double a){ height = h; age = a; public Dog (double a){ age = a; height = 0.5;
10 public class testdog{ public static void main(string[] str) { Dog d1 = new Dog(1); Dog d2 = new Dog(1.5, 2); swap(d1,d2); System.out.println("d1's age = "+d1.age); public static void swap(dog dog1, Dog dog2) { Dog temp = dog1; dog1 = dog2; dog2 = temp; System.out.println("dog1's age = "+dog1.age); public class Dog{ public double height; public double age; public Dog (double h, double a){ height = h; age = a; public Dog (double a){ age = a; height = 0.5;
11 tostring( ) in objects To be able to print the Objects, you need to implement a method in your class called tostring( ). This helps you print the object just by using the object name as any other primitive type variable. Example: public String tostring() { return "Dog's height = "+height+", and Dog's age = "+age; //in main method: Dog d = new Dog (1.5, 2); System.out.prinln(d); Output: Dog's height = 1.5, and Dog's age = 2.0
12 ArrayList
13 ArrayList Resizeable version of array that includes the useful operations: add, delete, check if value exists, etc.
14 Different Levels of Control Driving a car Do not need to think about how the engine works! If you did, it would be bad. Only have to: hit the gas/brake, turn the wheel at appropriate times. We've abstracted the notion of driving a car.
15 Different Levels of Control Some objects give us more or less control, and be at different levels of abstraction. Car analogy: manual transmission vs. automatic transmission. Trade-off: level of control vs. simplicity to use array higher lower ArrayList lower higher
16 ArrayList Represents the notion of an array, without having to think about the details of how an array works. Must still contain values of the same type!
17 ArrayList of Any Reference Type ArrayList <reference_type_name> (The < > is actually part of the syntax) e.g., ArrayList<String> ArrayList<Scanner> ArrayList<Cat> But not ArrayList<int> ArrayList<boolean>
18 Using an ArrayList An ArrayList is an Object, so you need the new keyword. import java.util.arraylist; ArrayList<String> myarray = new ArrayList<String>();
19 Common Methods til/arraylist.html Notice how the type is referred as E. add(e e) add(int index, E element) clear() get(int index) indexof(object o) remove(object o) remove(int index) size()
20 Example: ArrayList of Names ArrayList<String> names = new ArrayList<String>(); names.add( Jon Stewart ); names.add( Stephen Colbert ); names.add(1, John Oliver ); //now let's print the names: for (int i=0; i < names.size(); i++) { System.out.println(names.get(i));
21 ArrayList of What? In Java, there is a notion of generics. Consider the following two problems: Given a String[] print the elements of the array. Given an int[] print the elements of the array.
22 Printing String[] public static void print(string[] array) { for (int i=0; i < array.length; i++) { System.out.println(array[i]);
23 Printing int[] public static void print (int[] array) { for (int i=0; i < array.length; i++) { System.out.println(array[i]);
24 Only Two Differences Method header is String vs. int In general, basic array operations are the same for any type, except for minor differences.
25 Clever Design of ArrayList Rather than separate types of ArrayLists depending on the type of value being stored, write code that is generic and works on any generic type. We can also define our own classes and methods that make use of generics, but you'll have to take more COMP courses for that.
26 Example: generic ArrayList import java.util.arraylist; public class arraylisttest { public static void main(string[] args) { ArrayList <Dog> dogarr = new ArrayList<Dog>(); ArrayList <String> strarr = new ArrayList<String>(); Dog d = new Dog(1.5); dogarr.add(new Dog(1.5,1)); dogarr.add(new Dog(1.5)); strarr.add("hello"); strarr.add("world"); printarray(dogarr); printarray(strarr); public static void printarray (ArrayList <?> arr) { for(int i=0;i<arr.size();i++) System.out.println(arr.get(i));
27 Try it out!! Write a new version of CatRescue that uses an ArrayList<Cat> instead of Cat[]. Hint: Add a separate int field to keep track of the capacity. This lets you ditch the null checks. Also, add a method, addcapacity(int change) to increase the capacity of the rescue operation by change. We've found more people willing to be foster cat parents.
28 Linked List
29 Data Structures Data structures are a way of organizing collections of data in the computer's memory. Examples of data structures we have seen so far: Arrays :
30 Data Structures Data structures are a way of organizing collections of data in the computer's memory. Examples of data structures we have seen so far: Objects : Point: Cat : //Attributes double age; String name; //Methods public Point(double a, String n)
31 Data Structures Data structures are a way of organizing collections of data in the computer's memory. Examples of data structures we have seen so far: ArrayList :
32 Linked Lists List of Objects linked to each other. Pictorial representation of a Linked list of Cat objects. Cat Cat Cat Cat
33 Linked Lists List of Objects linked to each other. Pictorial representation of a Linked list of Cat objects. Cat Cat Cat Cat
34 Linked Lists List of Objects linked to each other. Pictorial representation of a Linked list of Cat objects. Cat Cat Cat Cat Next Data Next Data Next Data Next Data
35 Linked Lists List of Objects linked to each other. Pictorial representation of a Linked list of Cat objects. Cat Cat Cat Cat Next Data Next Data Next Data Next Data
36 Linked Lists Pictorial representation of a Linked list of Cat objects. Cat Cat Cat Cat Next Data Node Next Data Node Next Data Node Next Data Node InsertEnd( ) InsertStart( ) InsertAt( ) Remove( ) Start Linked List Nothing
37 Linked Lists Pictorial representation of a Linked list of int values. Linked List Start = Data = 3 Data = 2 Data = 5 Data = 1 Data = 7 Next = Next = Next = Next = Next = null Node Node Node Node Node
38 Building our Linked List We need to define a class for each element in the list: the Node class The Node class should have: A pointer to some data. We will call it its data. For simplicity, we will hold int numbers in our LinkedList. A pointer to the next element in the list. Unsurprisingly, we will call it next.
39 Building our Linked List public class Node { private int data; private Node next; // add a constructor here // add getter and setter methods here
40 Building our Linked List We need to define a class for doing operations on the list: the LinkedList class. The LinkedList class should have: A pointer to the first element in the list. We will call it start. All the methods with the operations we want to make on the list.
41 Building our Linked List public class LinkedList { private Node start; // add a constructor here // add Insertion, search and deletion methods here
42 Methods for our Linked List Inserting a node at the beginning of the List. Linked List Start = Data = 9 Next = null new Node Data = 3 Data = 2 Data = 5 Data = 1 Data = 7 Next = Next = Next = Next = Next = null Node Node Node Node Node
43 Methods for our Linked List Inserting a node at the end of the List. Linked List Start = Data = 3 Data = 2 Data = 5 Data = 1 Data = 7 Next = Next = Next = Next = Next = null Node Node Node Node Node Data = 9 Next = null new Node
44 Methods for our Linked List Inserting a node in the middle of the List (Between 5 and 1). Linked List Start = Data = 9 Next = null new Node Data = 3 Data = 2 Data = 5 Data = 1 Data = 7 Next = Next = Next = Next = Next = null Node Node Node Node Node
45 Methods for our Linked List Removing a node from the List (Remove node with Data = 5). Linked List Start = Data = 3 Data = 2 Data = 5 Data = 1 Data = 7 Next = Next = Next = Next = Next = null Node Node Node Node Node
46 Methods for our Linked List Removing a node from the List (Remove node with Data = 5). Linked List Start = Data = 3 Data = 2 Data = 1 Data = 7 Next = Next = Next = Next = null Node Node Node Node
47 Summary Review on Classes and Objects ArrayList Linked List
Garbage Collection (1)
Coming up: Today: Finish unit 6 (garbage collection) start ArrayList and other library objects Wednesday: Complete ArrayList, basics of error handling Friday complete error handling Next week: Recursion
More informationCOMP-202 Unit 7: More Advanced OOP. CONTENTS: ArrayList HashSet (Optional) HashMap (Optional)
COMP-202 Unit 7: More Advanced OOP CONTENTS: ArrayList HashSet (Optional) HashMap (Optional) Managing a big project Many times, you will need to use an Object type that someone else has created. For example,
More informationCOMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 Announcements Assignment 4 is posted and Due on 29 th of June at 11:30 pm. Course Evaluations due
More informationCOMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 13: Recursion Sandeep Manjanna, Summer 2015 Announcements Final exams : 26 th of June (2pm to 5pm) @ MAASS 112 Assignment 4 is posted and Due on 29 th of June
More informationCOMP-202: Foundations of Programming. Lecture 10: Method Overloading and Passing Objects to Methods. Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 10: Method Overloading and Passing Objects to Methods. Sandeep Manjanna, Summer 2015 Announcements Assignment 3: Due on 14 th of June at 11:30 pm. Midterm grades
More informationBig O & ArrayList Fall 2018 Margaret Reid-Miller
Big O & ArrayList 15-121 Fall 2018 Margaret Reid-Miller Today Exam 1: Thursday, Oct 4, 2018 Exam 2 date: Currently Thur. Oct 25 th Move to Tues Oct 30 or Thur Nov 1? (Withdraw deadline Tues Nov 6.) Homework
More informationCOMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016 Announcements Final is scheduled for Apr 21, 2pm 5pm GYM FIELD HOUSE Rows 1-21 Please submit course evaluations!
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationCOMP200 GENERICS. OOP using Java, from slides by Shayan Javed
1 1 COMP200 GENERICS OOP using Java, from slides by Shayan Javed 2 ArrayList and Java Generics 3 Collection A container object that groups multiple objects 4 Collection A container object that groups multiple
More informationArrayLists. Readings and References. Collections in the Real World. How can we manage lists of objects? Reading. Other References
Readings and References ArrayLists Reading» Chapter 14 and 17, Introduction to Programming in Java, Dugan CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/
More informationArrayLists. CSE 142, Summer 2002 Computer Programming 1.
ArrayLists CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-July-2002 cse142-09-arraylists 2002 University of Washington 1 Reading Readings and References»
More informationCOMP-202: Foundations of Programming. Lecture 5: Arrays, Reference Type, and Methods Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 5: Arrays, Reference Type, and Methods Sandeep Manjanna, Summer 2015 Announcements Assignment 2 posted and due on 30 th of May (23:30). Extra class tomorrow
More informationCSC 240 Computer Science III Spring 2018 Midterm Exam. Name
CSC 240 Computer Science III Spring 2018 Midterm Exam Name Page Points Score 2 9 4-6 53 7-10 38 Total 100 1 P age 1. Tracing programs (1 point each value): For each snippet of Java code on the left, write
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More information1. ArrayList and Iterator in Java
1. ArrayList and Iterator in Java Inserting elements between existing elements of an ArrayList or Vector is an inefficient operation- all element after the new one must be moved out of the way which could
More informationInterfaces, collections and comparisons
תכנות מונחה עצמים תרגול מספר 4 Interfaces, collections and comparisons Interfaces Overview Overview O Interface defines behavior. Overview O Interface defines behavior. O The interface includes: O Name
More informationBuilding a social network
Objects and classes Building a social network Suppose you're in the year 2004 and had this great idea... of a website where people could spend countless hours uploading personal information, writing messages
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationArrays and ArrayLists. David Greenstein Monta Vista High School
Arrays and ArrayLists David Greenstein Monta Vista High School Array An array is a block of consecutive memory locations that hold values of the same data type. Individual locations are called array s
More informationLecture 6: ArrayList Implementation
Lecture 6: ArrayList Implementation CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Programming Assignment Weak AI/Natural Language Processing: Generate text by building frequency lists based
More informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationLists using ArrayList
Lists using ArrayList 1 ArrayList One of the drawbacks of arrays is that they do not make it easy to accommodate collections of arbitrary size. We have to commit ourselves to a fixed size when we introduce
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More informationWeek 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5
CS2852 Exam 1 Name: No note-sheets, calculators, or other study aids on this exam. Write your initials at the top of each page except this one. Read through the whole exam before you get started. Have
More informationThe ArrayList class CSC 123 Fall 2018 Howard Rosenthal
The ArrayList class CSC 123 Fall 2018 Howard Rosenthal Lesson Goals Describe the ArrayList class Discuss important methods of this class Describe how it can be used in modeling Much of the information
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 6 ArrayLists
CSE 1223: Introduction to Computer Programming in Java Chapter 6 ArrayLists 1 A programming problem Consider the following task: Double values representing grades are read until the user enters a negative
More informationCS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction
More information11-1. Collections. CSE 143 Java. Java 2 Collection Interfaces. Goals for Next Several Lectures
Collections CSE 143 Java Collections Most programs need to store and access collections of data Collections are worth studying because... They are widely useful in programming They provide examples of
More informationCS 231 Data Structures and Algorithms Fall 2018
CS 231 Data Structures and Algorithms Fall 2018 Interface, Node Based Stack, Exception Handling, Class BufferedReader Lecture 12 October 1, 2018 Prof. Zadia Codabux 1 Agenda Node based implementation of
More informationTREES Lecture 12 CS2110 Fall 2016
TREES Lecture 12 CS2110 Fall 2016 Prelim 1 tonight! 2 5:30 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal 5:30 prelim (not the quiet room) and whose last names
More informationCOMP-202: Foundations of Programming. Lecture 9: Classes and Objects Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 9: Classes and Objects Sandeep Manjanna, Summer 2015 Announcements Assignment 3: Due on 14 th of June at 11:30 pm. Small Software Glitch Costing Huge The spacecraft
More informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More informationCS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.
Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationpublic static void main(string args[]){ arraylist(); recursion();
public class June16 { public static void main(string args[]){ arraylist(); recursion(); public static void recursion() { recursion(); //class goes on forever:( Example: ArrayList Are you sick of having
More informationCS 1331 Exam 1 ANSWER KEY
CS 1331 Exam 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in
More informationCOSC 123 Computer Creativity. Java Lists and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Java Lists and Arrays Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Objectives 1) Create and use arrays of base types and objects. 2) Create
More informationCS231 - Spring 2017 Linked Lists. ArrayList is an implementation of List based on arrays. LinkedList is an implementation of List based on nodes.
CS231 - Spring 2017 Linked Lists List o Data structure which stores a fixed-size sequential collection of elements of the same type. o We've already seen two ways that you can store data in lists in Java.
More informationCOMP-202. Generics. COMP Generics, 2013 Jörg Kienzle and others
COMP-202 Generics Objects and Casting Generics Instantiation Usage ArrayList Iterators Iterator Lecture Outline 2 Objects and Casting All instances of all classes in Java are also of the class Object
More information01. Which of the following statement describes dynamic resizing as is applies to the ArrayList class?
Exposure Java Chapter 11 Multiple Choice Test ArrayList Class DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions with the assumption that
More informationJava Collections Framework: Interfaces
Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection Interface The List Interface The Iterator Interface The ListIterator
More informationCOMP-202: Foundations of Programming. Lecture 16: Reference types Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 16: Reference types Jackie Cheung, Winter 2016 Warm Up Without looking at our code from the last lecture, let s write a Cat class. Fields: String name double
More informationList ADT. Announcements. The List interface. Implementing the List ADT
Announcements Tutoring schedule revised Today s topic: ArrayList implementation Reading: Section 7.2 Break around 11:45am List ADT A list is defined as a finite ordered sequence of data items known as
More informationArray Based Lists. Collections
Array Based Lists Reading: RS Chapter 15 1 Collections Data structures stores elements in a manner that makes it easy for a client to work with the elements Specific collections are specialized for particular
More informationCOE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015
1 COE 212 Engineering Programming Welcome to the Final Exam Tuesday December 15, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.
More informationCSE 143. Lecture 13: Interfaces, Comparable reading: , 16.4, 10.2
CSE 143 Lecture 13: Interfaces, Comparable reading: 9.5-9.6, 16.4, 10.2 Related classes Consider classes for shapes with common features: Circle (defined by radius r ): area = r 2, perimeter = 2 r Rectangle
More informationProgramming in the Large II: Objects and Classes (Part 1)
Programming in the Large II: Objects and Classes (Part 1) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ ABSTRACT DATATYPES 2 Abstract Datatype (ADT)
More informationHomework 2: Imperative Due: 5:00 PM, Feb 15, 2019
CS18 Integrated Introduction to Computer Science Fisler Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019 Contents 1 Overview of Generic/Parameterized Types 2 2 Double the Fun with Doubly-Linked Lists
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationFinal Exam. COMP Summer I June 26, points
Final Exam COMP 14-090 Summer I 2000 June 26, 2000 200 points 1. Closed book and closed notes. No outside material allowed. 2. Write all answers on the test itself. Do not write any answers in a blue book
More informationImplementing a List in Java. CSE 143 Java. Just an Illusion? List Interface (review) Using an Array to Implement a List.
Implementing a List in Java CSE 143 Java List Implementation Using Arrays Reading: Ch. 13 Two implementation approaches are most commonly used for simple lists: Arrays Linked list Java Interface List concrete
More information2. [20] Suppose we start declaring a Rectangle class as follows:
1. [8] Create declarations for each of the following. You do not need to provide any constructors or method definitions. (a) The instance variables of a class to hold information on a Minesweeper cell:
More informationBuilding Java Programs
Building Java Programs Chapter 16 References and linked nodes reading: 16.1 2 Value semantics value semantics: Behavior where values are copied when assigned, passed as parameters, or returned. All primitive
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming
More informationData abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003
Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation
More informationCS 302: Introduction to Programming in Java. Lecture 12
CS 302: Introduction to Programming in Java Lecture 12 1 Review What is the 3-step processing for using Objects (think Scanner and Random)? Do objects use static methods or non-static (how do you know)?
More informationRecitation 3 Class and Objects
1.00/1.001 Introduction to Computers and Engineering Problem Solving Recitation 3 Class and Objects Spring 2012 1 Scope One method cannot see variables in another; Variables created inside a block: { exist
More informationCOMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 Announcements Check the calendar on the course webpage regularly for updates on tutorials and office hours.
More informationCollections class Comparable and Comparator. Slides by Mark Hancock (adapted from notes by Craig Schock)
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationLecture 15 Summary. Collections Framework. Collections class Comparable and Comparator. Iterable, Collections List, Set Map
Lecture 15 Summary Collections Framework Iterable, Collections List, Set Map Collections class Comparable and Comparator 1 By the end of this lecture, you will be able to use different types of Collections
More informationCSE 113 A. Announcements - Lab
CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure
More informationJava Language Features
Java Language Features References: Object-Oriented Development Using Java, Xiaoping Jia Internet Course notes by E.Burris Computing Fundamentals with Java, by Rick Mercer Beginning Java Objects - From
More informationCS1150 Principles of Computer Science Objects and Classes
CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8
More informationEXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction
More informationSlides are adapted from the originals available at
C H A P T E R 1 1! Arrays and ArrayLists Little boxes, on a hillside, little boxes made of ticky-tacky Little boxes, little boxes, little boxes, all the same There s a green one and a pink one and a blue
More informationCS 1331 Fall 2016 Exam 3 Part 1 ANSWER KEY
CS 1331 Fall 2016 Exam 3 Part 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are
More informationModel Solutions. COMP 103: Mid-term Test. 19th of August, 2016
Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 45 minutes
More informationLecture 17. Instructor: Craig Duckett. Passing & Returning Arrays
Lecture 17 Instructor: Craig Duckett Passing & Returning Arrays Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section
More informationJava Collections. Readings and References. Collections Framework. Java 2 Collections. References. CSE 403, Winter 2003 Software Engineering
Readings and References Java Collections References» "Collections", Java tutorial» http://java.sun.com/docs/books/tutorial/collections/index.html CSE 403, Winter 2003 Software Engineering http://www.cs.washington.edu/education/courses/403/03wi/
More informationLast Name: Circle One: OCW Non-OCW
First Name: AITI 2004: Exam 1 June 30, 2004 Last Name: Circle One: OCW Non-OCW Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot
More informationQuestion 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.
CSE 143 Sp04 Midterm 2 Page 1 of 10 Reference information about some standard Java library classes appears on the last pages of the test. You can tear off these pages for easier reference during the exam
More informationJava Review: Objects
Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation
More informationReview questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,
April 1, 2003 1 Previous Lecture: Intro to OOP Class definition: instance variables & methods Today s Lecture: Instance methods Constructors Methods with input parameters Review questions Where do you
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Final Examination Wednesday, December 16, 2009 Examiners: Mathieu Petitpas
More informationInstance Method Development Demo
Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write
More informationImplementing a List in Java. CSE 143 Java. List Interface (review) Just an Illusion? Using an Array to Implement a List.
Implementing a List in Java CSE 143 Java List Implementation Using Arrays Reading: Ch. 22 Two implementation approaches are most commonly used for simple lists: Arrays Linked list Java Interface List concrete
More informationClasses and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?
Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable
More informationTopic #9: Collections. Readings and References. Collections. Collection Interface. Java Collections CSE142 A-1
Topic #9: Collections CSE 413, Autumn 2004 Programming Languages http://www.cs.washington.edu/education/courses/413/04au/ If S is a subtype of T, what is S permitted to do with the methods of T? Typing
More informationInheritance and Interfaces
Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance
More informationCS 1302 Chapter 9 (Review) Object & Classes
CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state
More informationCS Week 14. Jim Williams, PhD
CS 200 - Week 14 Jim Williams, PhD This Week 1. Final Exam: Conflict Alternatives Emailed 2. Team Lab: Object Oriented Space Game 3. BP2 Milestone 3: Strategy 4. Lecture: More Classes and Additional Topics
More informationSTUDENT LESSON A15 ArrayList
STUDENT LESSON A15 ArrayList Java Curriculum for AP Computer Science, Student Lesson A15 1 STUDENT LESSON A15 - ArrayList INTRODUCTION: It is very common for a program to manipulate data that is kept in
More informationCOMP 401 Spring 2014 Midterm 1
COMP 401 Spring 2014 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page
More informationCSSE 220 Day 8. Arrays, ArrayLists, Wrapper Classes, Auto-boxing, Enhanced for loop. Check out ArraysAndLists from SVN
CSSE 220 Day 8 Arrays, ArrayLists, Wrapper Classes, Auto-boxing, Enhanced for loop Check out ArraysAndLists from SVN Questions? Exam 1 is October 1, 7-9 PM! Over chapters 1-7 You'll have a chance to ask
More informationCOE318 Lecture Notes Week 13 (Nov 28, 2011)
COE318 Software Systems Lecture Notes: Week 13 1 of 8 COE318 Lecture Notes Week 13 (Nov 28, 2011) Topics Review Questions/Answers K. Clowes counselling hours for exam week Counselling Hours for Exam Week
More informationBuilding Java Programs
Building Java Programs Chapter 15 Lecture 15-1: Implementing ArrayIntList reading: 15.1-15.3 Recall: classes and objects class: A program entity that represents: A complete program or module, or A template
More informationSpring, 2014 CIT 590. Programming Languages and Techniques Homework 7
Spring, 2014 CIT 590 Programming Languages and Techniques Homework 7 Mar 21, 2014; Due Mar 28, 2014, before first recitation This homework deals with the following topics * Getting started with Java *
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 07: Linked Lists MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Linked Lists 2 Introduction Linked List Abstract Data Type SinglyLinkedList ArrayList Keep in Mind Introduction:
More informationWhat will this print?
class UselessObject{ What will this print? int evennumber; int oddnumber; public int getsum(){ int evennumber = 5; return evennumber + oddnumber; public static void main(string[] args){ UselessObject a
More informationCSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
More informationProgramming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures
Chapter 4: Control Structures I Java Programming: Program Design Including Data Structures Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form
More information141214 20219031 1 Object-Oriented Programming concepts Object-oriented programming ( תכנות מונחה עצמים ) involves programming using objects An object ) (עצם represents an entity in the real world that
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationPrinciples of Object Oriented Programming. Lecture 4
Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance
More informationTREES. Tree Overview 9/28/16. Prelim 1 tonight! Important Announcements. Tree terminology. Binary trees were in A1!
//16 Prelim 1 tonight! :3 prelim is very crowded. You HAVE to follow these directions: 1. Students taking the normal :3 prelim (not the quiet room) and whose last names begin with A through Da MUST go
More informationLecture 7 Objects and Classes
Lecture 7 Objects and Classes An Introduction to Data Abstraction MIT AITI June 13th, 2005 1 What do we know so far? Primitives: int, double, boolean, String* Variables: Stores values of one type. Arrays:
More information