

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Assignment; Class: Intro to Computer Science I; Subject: Computer Science; University: University of San Francisco (CA); Term: Spring 2008;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!
CS 110: Introduction to Computer Science Spring 2008
In this lesson, we’ll learn more about built-in arrays, ArrayList, and Java library classes in general. To do this, we’ll talk about how the ArrayList class in the Java library is implemented.
ArrayList is a class that 'wraps' Java's built-in array, providing a list that can grow. It is generic, in that one can use ArrayList for a list with elements of any type. We’ll begin with an IntArray class that wraps a built-in integer array. Instructor coding : Write an IntArray class with append and get:
CS 110: Introduction to Computer Science Spring 2008 In-class assignment 1: Modify IntArray so that it will grow as needed.
The Java library provides a special class called 'Object' which can be thought of as a generic placeholder. If you define a formal parameter to be of type 'Object', then you can send an object of any class type as the actual parameter. So if in class Foo there is a function defined as: void func(Object object) it can be called with: Foo f = new Foo(); f.func(person); f.func(car) f.func(token) where person, car, and token are objects of the types Person, Car, or Token. class Object is used to implement Java's ArrayList—the append method of ArrayList accepts an item of any type. In class Problem 2. Copy your IntArray class and name the copy 'ArrList'. Modify the code so that the built-in array data member is of type Object and the 'add' and 'get' methods work on Object instead of int. To test your new class, add your Person and Car classes into the project, and write a main in your ArrList class that creates lists of each of these.