Cmpt 225
Simon Fraser University
School of Computing Science
Cmpt 225 - Lab #2
Abstract Data Type, Interface, and Object Class
Objectives
Our objectives in this Lab #2 is to become familiar with abstract data
types, Java interfaces and the Java Object class. Specifically,
we will learn...
-
How to construct an abstract data type (ADT) class
-
How to use Java interfaces, more specifically the "Comparable"
Java interface
-
What is the class Object and how it is used
-
How to cast using a Java interface
-
The operator precedence
-
The containment relationship amongst two classes
Problem Statement and Specific Requirements
In this lab we are to modify the Student Registration and Grades application
we developed in Lab #1. More specifically, we have to ...
-
In order to simplify the manipulation of students
within our application, replace our array
with a List abstract data type (ADT) class called List.java.
This List abstract data type (ADT) class must be an index-based data collection,
i.e., its underlying data structure is an array. Store the students in
an instance of this List ADT class.
-
Your List ADT class must provide the following functionality:
-
insert an element
-
delete an element
-
return the number of elements currently stored in
the list
-
check if a specific element is in the list
-
Design and implement your List ADT class such that
you should be able to store student objects (from Lab #1) into it as well
as other objects such as Integer and Double objects.
Can two Integer objects be compared against each other? Can
two Double objects be compared against each other? To be
able to answer these questions, check these two classes in the Java API.
You will need this functionality (comparison) to insert and delete specific
elements to and from the List.
-
Create a test class to test your List ADT class.
Test your List using
-
integers
-
students
-
and any other objects
and make sure that, for each list of objects above,
you exercise all the functions of your List ADT class.
-
NOTE: this List ADT class is a more general tool
than we need for this particular task. This implies that we may not make
use of all of its methods but only the ones that make sense for the application
we are developing.
Suggestions
-
Investigate the Java interface Comparable.
-
Be careful with operator precedence.
Resources
The first thing we will need to do is investigate and read about the topics
listed above in the Objectives section . Below are partial lists
of books and web sites you may wish to look at in order to perform your
investigation.
List of books:
List of web sites:
As stated, the above lists are not exhaustive, therefore feel free to add
to them the Java books and web sites you find useful. Also, feel free to
send these (books and URL's) to the instructor so that they can be added
to this lab and to our course web site.
Anne Lavergne and Zhi Hao Lin - January
2005 - Last Revision date August 2006