What does this output? Is there a better way to say the same thing? What does this do? Is there a better way to say the same thing?
|
|
- Egbert Thompson
- 5 years ago
- Views:
Transcription
1 public class Person { protected String name; public Person (String name) { public String getname() { return name; public class Student extends Person {... public String getname() { return super.getname(); What does this output? Is there a better way to say the same thing? Student s = new Student ( Julie ); System.out.println (s.getname()); 1 public class Person { protected String name; public Person (String name) { public String getname() { return name; public class Student extends Person { public Student (String name) { super(name); What does this do? Is there a better way to say the same thing? 2
2 public class Person { protected String name; public Person (String name) { public class Student extends Person { private int age; public Student (String name, int age) { super(name); this.age = age; Is there a better way to say the same thing? public class Alum extends Person { private int age; public Alum (String name, int age) { super(name); this.age = age; 3 public class Person { protected String name; public Person (String name) { public class Student extends Person { private int age; public Student (String name, int age) { super(name); this.age = age; public class Person { protected String name; protected int age; public Person (String name, int age) { this.age = age; public class Student extends Person { public Student (String name, int age) super(name, age); public class Alum extends Person { private int age; public Alum (String name, int age) { super(name); this.age = age; public class Alum extends Person { public Alum (String name, int age) { super(name, age); 4
3 public class AsteroidGameShape { public class Asteroid extends AsteroidGameShape { private static final int SPEED = 2; public void move() { top = top + SPEED; public class Ship extends AsteroidGameShape { private int speed = 0; public void move() { top = top + speed; private void setspeed (int newspeed) { speed = newspeed; Is there a better way to say the same thing? 5 public class AsteroidGameShape { public class Asteroid extends AsteroidGameShape { private static final int SPEED = 2; public void move() { top = top + SPEED; public class Ship extends AsteroidGameShape { private int speed = 0; public void move() { top = top + speed; private void setspeed (int newspeed) { speed = newspeed; public class AsteroidGameShape { protected int speed; public AsteroidGameShape (int speed) { this.speed = speed; public void move() { top = top + SPEED; public class Asteroid extends AsteroidGameShape { private static final int SPEED = 2; public Asteroid() { super (SPEED); public class Ship extends AsteroidGameShape { public Ship() { super(0); private void setspeed (int newspeed) { speed = newspeed; 6
4 Arrays What can we do with arrays? Manage collections of information Put a value into an array a[i] = 1; Get a value out of an array value = a[i]; Ask the array what its size is size = a.length; 7 Fixed in size Array Limitation 1 How do we get around this? Make the array as big as we think it ever needs to be Add another data member to the class that remembers how many entries are in the array Example from Asteroids extra credit: int bullets[1000]; int numbullets; 8
5 Array Limitation 2 Adding an element at a specific position (as opposed to replacing an element) may require moving other elements public void insertinfront(int value) throws ArrayFullException { if (numelements == a.length) { throw new ArrayFullException(); for (int i = numelements; i > 0; i--) { a[i] = a[i-1]; a[0] = value; numelements++; 9 Array Limitation 3 Removing an element at a specific position may require moving elements to avoid gaps public int removefromfront() throws ArrayEmptyException { if (numelements == 0) { throw new ArrayEmptyException(); int returnvalue = a[0]; for (int i = 0; i < numelements-1; i++) { a[i] = a[i+1]; numelements--; return returnvalue; 10
6 Wouldn t it be nice if... Collections could change size as necessary Inserting into a specific position was as easy as assigning to an array element Removing an element was easy ArrayLists to the rescue!! 11 Interface java.util.list Array-like operations: public void set (int index, Object o) public Object get (int index) public int size() Insertion and removal: public void add (Object o) public void add (int index, Object o) public Object remove (int index) public boolean remove (Object o) Other useful operations: public boolean contains (Object o) public int indexof (Object o) 12
7 Arrays vs Lists Can change size Arrays No Lists Yes Random access Yes Yes Easy insertion & removal Elements can be any type No Yes Yes No 13 <<interface>> List <<abstract>> AbstractList ArrayList LinkedList 14
8 ArrayList Implements all methods from List interface Random access like arrays Easy insertion & removal Search operations Can grow as necessary Has a capacity in addition to a current size public ArrayList() public ArrayList (int initialcapacity) public void ensurecapacity (int mincapacity) public void trimtosize() 15 ArrayList Methods Kelsey Kira.add( Mindan ); Kelsey Kira Mindan.add( Carol, 0); Carol Kelsey Kira Mindan.set( Cade, 0) returns Carol Cade Kelsey Kira Mindan 16
9 ArrayList Methods Cade Kelsey Kira Mindan.contains( Kira ) returns true.indexof( Kelsey ) returns 1.get(2) returns Kira 17 ArrayList Methods Cade Kelsey Kira Mindan.remove( Kelsey ) returns true Cade Kira Mindan.remove( Tricia ) returns false.remove(0) returns Cade Kira Mindan.remove(2) throws IndexOutOfBoundsException.add(5, Sarah ) throws IndexOutOfBoundsException 18
10 Declaring and Constructing an ArrayList // Construct an ArrayList that can hold Strings ArrayList<String> links = new ArrayList<String>(); 19 Javadoc for Generics Class ArrayList<E> boolean add (E e) E get (int index) E remove (int index) E set (int index, E element) There is no type named E Means whatever type parameter is used in the declaration ArrayList<String> links; -> add and set must be passed Strings -> get, remove and set will return Strings 20
Lecture 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 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 informationAbstract classes are used to define a class that will be used only to build new classes. No objects will ever be instantiated from an abstract class.
Abstract classes are used to define a class that will be used only to build new classes. No objects will ever be instantiated from an abstract class. Mammal (abstract class) Human Whale Cow Any sub class
More informationWinter 2016 COMP-250: Introduction to Computer Science. Lecture 6, January 28, 2016
Winter 2016 COMP-250: Introduction to Computer Science Lecture 6, January 28, 2016 Java Generics element next _, Java Generics Java Generics (Doubly) Linked List (Doubly) Linked List Node element next
More informationGenerics. IRS W-9 Form
Generics IRS W-9 Form Generics Generic class and methods. BNF notation Syntax Non-parametrized class: < class declaration > ::= "class" < identifier > ["extends" < type >] ["implements" < type list >]
More informationAdvanced Java Concepts Unit 2: Linked Lists.
Advanced Java Concepts Unit 2: Linked Lists. The List interface defines the structure of a linear collection. Here are some of its methods. boolean add( E element ) Appends the element to the end of the
More informationCSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,
CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding
More informationCSE 143 Au03 Midterm 2 Page 1 of 7
CSE 143 Au03 Midterm 2 Page 1 of 7 Question 1. (4 points) (a) If a precondition is not true when a method is called, two possible ways to detect and handle the situation are to use an assert statement
More informationSolutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.
Solutions Manual Data Structures and Algorithms in Java, 5th edition International Student Version M. T. Goodrich and R. Tamassia Chapter 1 Reinforcement Solution R-1.1 Since, after the clone, A[4] and
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 informationWhat is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one
Iterators What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one 9-2 2-2 What is an Iterator? An iterator is an abstract data
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 informationCollections Algorithms
Collections Algorithms 1 / 11 The Collections Framework A collection is an object that represents a group of objects. The collections framework allows different kinds of collections to be dealt with in
More informationImplementing a List in Java. CSC 143 Java. List Interface (review) Just an Illusion? Using an Array to Implement a List CSC
Implementing a List in Java CSC 143 Java List Implementation Using Arrays Updated with Java 5.0 Generics Reading: Ch. 13 Two implementation approaches are most commonly used for simple lists: Arrays Linked
More informationCS 151. Exceptions & Javadoc. slides available on course website. Sunday, September 9, 12
CS 151 Exceptions & Javadoc slides available on course website 1 Announcements Prelab 1 is due now. Please place it in the appropriate (Mon vs. Tues) box. Please attend lab this week. There may be a lecture
More informationVector (Java 2 Platform SE 5.0) Overview Package Class Use Tree Deprecated Index Help
Overview Package Class Use Tree Deprecated Index Help PREV CLASS NEXT CLASS FRAMES NO FRAMES All Classes SUMMARY: NESTED FIELD CONSTR METHOD DETAIL: FIELD CONSTR METHOD Página 1 de 30 Java TM 2 Platform
More informationAbstract Data Types (ADTs) Example ADTs. Using an Abstract Data Type. Class #08: Linear Data Structures
Abstract Data Types (ADTs) Class #08: Linear Data Structures Software Design III (CS 340): M. Allen, 08 Feb. 16 An ADT defines a kind of computational entity: A set of objects, with possible values A set
More informationLinked Lists. What Is A Linked List? Example Declarations. An Alternative Collections Data Structure. Head
Linked Lists An Alternative Collections Data Structure What Is A Linked List? A data structure using memory that expands and shrinks as needed Relies on identical nodes pointing or linked to other nodes
More informationAdvanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II
Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic
More informationAPCS Semester #1 Final Exam Practice Problems
Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester
More informationCSE 143 Au03 Midterm 2 Sample Solution Page 1 of 7
CSE 143 Au03 Midterm 2 Sample Solution Page 1 of 7 Question 1. (4 points) (a) If a precondition is not true when a method is called, two possible ways to detect and handle the situation are to use an assert
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 informationObject Oriented Programming and Design in Java. Session 2 Instructor: Bert Huang
Object Oriented Programming and Design in Java Session 2 Instructor: Bert Huang Announcements TA: Yipeng Huang, yh2315, Mon 4-6 OH on MICE clarification Next Monday's class canceled for Distinguished Lecture:
More informationCS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle
Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the
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 informationCMSC 433 Section 0101 Fall 2012 Midterm Exam #1
Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Directions: Test is closed book, closed notes. Answer every question; write solutions in spaces provided. Use backs of pages for scratch work. Good
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 informationArray based Bag and List Implementations
Lab 5 Array based Bag and List Implementations Goal Having worked with Bags and Lists in previous labs, we are now going to pull the covers off them and learn how they are constructed and how they work
More informationLesson 2.4 Arraylist
Lesson 24 Arraylist Mimi Duong Rosalba Rodriguez Java Crash Course January 6th, 2015 Data Structure ArrayLists Live Coding Methods Searching Through ArrayLists Classwork Storing Items in Java How have
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 informationCISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.
CISC-124 20180215 These notes are intended to summarize and clarify some of the topics that have been covered recently in class. The posted code samples also have extensive explanations of the material.
More informationList ADT. B/W Confirming Pages
wu3399_ch8.qxd //7 :37 Page 98 8 List ADT O b j e c t i v e s After you have read and studied this chapter, you should be able to Describe the key features of the List ADT. the List ADT using an array
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 informationCISC 3115 TY3. C24a: Lists. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 11/15/2018 CUNY Brooklyn College
CISC 3115 TY3 C24a: Lists Hui Chen Department of Computer & Information Science CUNY Brooklyn College 11/15/2018 CUNY Brooklyn College 1 Outline Concept of data structure Use data structures List Stack
More informationSum this up for me. Let s write a method to calculate the sum from 1 to some n. Gauss also has a way of solving this. Which one is more efficient?
Sum this up for me Let s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
More informationCS 151. Linked Lists, Recursively Implemented. Wednesday, October 3, 12
CS 151 Linked Lists, Recursively Implemented 1 2 Linked Lists, Revisited Recall that a linked list is a structure that represents a sequence of elements that are stored non-contiguously in memory. We can
More informationLecture 9: Lists. MIT-AITI Kenya 2005
Lecture 9: Lists MIT-AITI Kenya 2005 1 In this lecture we will learn. ArrayList These are re-sizeable arrays LinkedList brief overview Differences between Arrays and ArrayLists Casting Iterator method
More informationMidterm Exam 2 CS 455, Fall 2014
Name: USC NetId (e.g., ttrojan): Midterm Exam 2 CS 455, Fall 2014 November 11, 2014 There are 8 problems on the exam, with 62 points total available. There are 8 pages to the exam, including this one;
More informationASSIGNMENT 4. COMP-202, Fall 2013, All Sections. Due: December 6 th,2013(23:59)
ASSIGNMENT 4 COMP-202, Fall 2013, All Sections Due: December 6 th,2013(23:59) Please read the entire PDF before starting. You must do this assignment individually and, unless otherwise specified, you must
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 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 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 information+ Abstract Data Types
Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract
More informationComputational Expression
Computational Expression Do While Loop, For Loop, Arrays Janyl Jumadinova 26 November, 2018 Janyl Jumadinova Computational Expression 26 November, 2018 1 / 18 Review: Repetition structures while() loop
More informationOutline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003
Outline Object Oriented Programming Autumn 2003 2 Course goals Software design vs hacking Abstractions vs language (syntax) Java used to illustrate concepts NOT a course about Java Prerequisites knowledge
More informationWeek 5-1: ADT Design
Week 5-1: ADT Design Part1. ADT Design Define as class. Every obejects are allocated in heap space. Encapsulation : Data representation + Operation Information Hiding : Object's representation part hides,
More informationQUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer
QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back
More informationCITS1001 week 6 Libraries
CITS1001 week 6 Libraries Arran Stewart April 12, 2018 1 / 52 Announcements Project 1 available mid-semester test self-assessment 2 / 52 Outline Using library classes to implement some more advanced functionality
More informationIT 313 Advanced Application Development
Page 1 of 7 IT 313 Advanced Application Development Practice Midterm Exam Part A. Multiple Choice Questions. Answer all questions. Optional: supply a reason or show work for partial credit in case you
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 informationCSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 7 pages. You may use your single-sided handwritten 8 ½ x 11 note sheet during
More informationImplements vs. Extends When Defining a Class
Implements vs. Extends When Defining a Class implements: Keyword followed by the name of an INTERFACE Interfaces only have method PROTOTYPES You CANNOT create on object of an interface type extends: Keyword
More informationAP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50
AP COMPUTER SCIENCE A DIAGNOSTIC EXAM Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50 Directions: Determine the answer to each of the following
More information11/2/ Dynamic Data Structures & Generics. Objectives. Array-Based Data Structures: Outline. Harald Gall, Prof. Dr.
12. Dynamic Data Structures & Generics Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch Objectives! Define and use an instance of ArrayList! Describe general idea
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 informationCOE318 Lecture Notes Week 8 (Oct 24, 2011)
COE318 Software Systems Lecture Notes: Week 8 1 of 17 COE318 Lecture Notes Week 8 (Oct 24, 2011) Topics == vs..equals(...): A first look Casting Inheritance, interfaces, etc Introduction to Juni (unit
More informationYes, it changes each time simulateonestep is invoked.
Exercise 10.1 Yes, the number of foxes changes. However, note that although this has a high probability of happening, it is not guaranteed to and will ultimately depend upon the initial state of the simulation.
More informationCollections. James Brucker
Collections James Brucker Collection A Collection is a group of objects. Set an unordered collection no duplicates List ordered collection duplicates are allowed can add or remove elements anywhere in
More informationAbout this sample exam:
About this sample exam: You may and SHOULD work through this exam yourself and discuss you answers with others. To find out the right answers to questions, type in the code to a compiler and run it. You
More informationReview: Array Initializer Lists
More on Arrays Review of Arrays of ints, doubles, chars Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 7.2 Reading for this lecture: L&L 7.3 7.7,
More informationCS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012
Name: USC loginid (e.g., ttrojan): CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 There are 6 problems on the exam, with 70 points total available. There are 7 pages to the exam, including this one;
More informationCSC 204 Lab 12: Intro to ArrayLists
CSC 204 Lab 12: Intro to ArrayLists Goals After doing this lab, you should be able to: declare and trace an ArrayLists work with ArrayLists of objects use the for statement to read in, process, and print
More informationCP222 Computer Science II. Linked Lists
CP222 Computer Science II Linked Lists Facebook data and Cambridge Analytica Tech News! Tech News! Facebook data and Cambridge Analytica Amazon now delivering Prime to car trunks Getting Help Fei CS Paraprof
More informationAdvanced Java Concept Unit 1. Mostly Review
Advanced Java Concept Unit 1. Mostly Review Program 1. Create a class that has only a main method. In the main method create an ArrayList of Integers (remember the import statement). Add 10 random integers
More informationAP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested.
AP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested. 1. The Nose class... b) will not compile because the m1 method parameter should be named n, not x. 2. The Ears class...
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 520 Theory and Practice of Software Engineering Fall 2018
Logistics CS 520 Theory and Practice of Software Engineering Fall 2018 Best and worst programming practices September 11, 2018 Reminder Recap: software architecture vs. design Class website: https://people.cs.umass.edu/~brun/class/2018fall/cs520/
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationRecitation 3/27/2009. CS 180 Department of Computer Science, Purdue University
Recitation 3/27/2009 CS 180 Department of Computer Science, Purdue University Announcements & Reminders Project 6 milestone is due today! Project 6 final due April 1st. Ask questions and spend time on
More informationJava Array List Interview Questions
Java Array List Interview Questions codespaghetti.com/arraylist-interview-questions/ Array List Java Array List Interview Questions, Algorithms and Array List Programs. Table of Contents: CHAPTER 1: Top
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 informationMidterm Exam 2 CS 455, Spring 2011
Name: USC loginid (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2011 March 31, 2011 There are 6 problems on the exam, with 50 points total available. There are 7 pages to the exam, including this one;
More informationCSC 172 Data Structures and Algorithms. Lecture #8 Spring 2018
CSC 172 Data Structures and Algorithms Lecture #8 Spring 2018 Project 1 due tonight Announcements Project 2 will be out soon Q & A Reminder: For sharing your concern anonymously, you can always go to:
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 informationC08: Inheritance and Polymorphism
CISC 3120 C08: Inheritance and Polymorphism Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/19/2017 CUNY Brooklyn College 1 Outline Recap and issues Project progress? Practice
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
Logistics CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Recap: software architecture vs. design Recap: software architecture examples
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationCS 520 Theory and Practice of Software Engineering Fall 2017
CS 520 Theory and Practice of Software Engineering Fall 2017 Best and worst programming practices September 12, 2017 Logistics Recap: software architecture vs. design Specification Architecture Development
More informationArrays. Chapter Arrays What is an Array?
Chapter 8 Arrays 81 Arrays 811 What is an Array? To motivate why we might be interested in using arrays, let us implement an app that creates a collection of doubles We will keep track of the number of
More informationCIT Special final examination
CIT 590-2016 Special final examination Name (please write your official name) PennID Number Note that your PennID number is the 8 digit bold number on your penn card. DO NOT START WRITING (aside from name
More informationGoals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #9. Review is-a versus has-a. Lecture #9 Inheritance I
CSE1030 Introduction to Computer Science II Lecture #9 Inheritance I Goals for Today Today we start discussing Inheritance (continued next lecture too) This is an important fundamental feature of Object
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More informationCS-140 Fall 2018 Test 2 Version A Nov. 12, Name:
CS-140 Fall 2018 Test 2 Version A Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) X T F : A class in Java contains fields, and
More informationCS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016
Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 There are 7 problems on the exam, with 50 points total available. There are 8 pages to the exam (4 pages double-sided),
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 informationArrayList. Introduction. java.util.arraylist
ArrayList Introduction In this article from my free Java 8 course, I will be giving you a basic overview of the Java class java.util.arraylist. I will first explain the meaning of size and capacity of
More informationWhat is Inheritance?
Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting
More informationUniversity of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Test 2 Question Max Mark Internal
More informationITI Introduction to Computing II
index.pdf March 17, 2013 1 ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 17, 2013 Definitions A List is a linear abstract
More informationCOMP-202: Foundations of Programming. Lecture 11: ArrayList, and Linked List Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 11: ArrayList, and Linked List Sandeep Manjanna, Summer 2015 Announcements Assignment 4 will be posted by the end of day today. Course Evaluations are now open.
More informationLast Week: Organizing Data. Last Week: Parallel Arrays. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu.
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Arrays of/in Objects Partially Filled Arrays ArrayLists Do-It-Yourself ArrayLists Readings Next Week: Ch 8.3-8.8 and into Ch 9.1-9.3
More informationCS 61B Discussion 5: Inheritance II Fall 2018
CS 61B Discussion 5: Inheritance II Fall 2018 1 Inheritance Practice public class Q { public void a() { System.out.println("Q.a"); public void b() { a(); public void c() { public void d() { public static
More informationPhoneBook (Array List)
PhoneBook (Array List) Background: You are to create a class that will mimic the actions of the speed dials in a cell phone. The user of your cell phone will have 10 speed dial numbers from 0-9. For each
More informationCPSC 211 MIDTERM PRACTICE EXERCISES
CPSC 211 MIDTERM PRACTICE EXERCISES Note: These questions are intended to help you practice and review the course material. Do not consider these questions as typical midterm questions; in particular,
More informationG51PGP Programming Paradigms. Lecture OO-4 Aggregation
G51PGP Programming Paradigms Lecture OO-4 Aggregation 1 The story so far We saw that C code can be converted into Java code Note real object oriented code though Hopefully shows you how much you already
More informationCS 61B Data Structures and Programming Methodology. July 2, 2008 David Sun
CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun Announcements Project 1 spec and code is available on the course website. Due July 15 th. Start early! Midterm I is next Wed in
More informationTeenCoder : Java Programming (ISBN )
TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+
More informationCollections. Collections Collection types Collection wrappers Composite classes revisited Collection classes Hashtables Enumerations
References: Beginning Java Objects, Jacquie Barker; The Java Programming Language, Ken Arnold and James Gosling; IT350 Internet lectures 9/16/2003 1 Collections Collection types Collection wrappers Composite
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 information