CS 1054 Introduction to Programming in Java (Spring 2008)
Lab 9: Arrays and array lists
Lab Objectives
- Learn how to write an aggregate class using an array
- Learn how to write an aggregate class using an array list
Instructions
- There will be no webcat submission for this week's lab,
but attendance will be checked.
You get twenty points for just paying attention.
The TA will walk you through most of the tasks,
but you will be given some time to implement some methods yourself.
- Begin by downloading
Lab9.zip,
save the file, and then extract it in a folder you can locate.
Open this project in BlueJ.
Make sure all classes (GradeRecord, ReportCard, and ReportCardTester) are compiled.
- We can view a ReportCard as an aggregate class:
a ReportCard object consists of multiple GradeRecord objects.
ReportCardTester
creates several ReportCard objects and adds, updates, and accesses
the grade records contained in these objects.
Study ReportCardTester and execute it, and make sense of the output it produces.
- ReportCard is implemented as containing an array of GradeRecord objects.
As it stands, it is a complete, fully working class.
- The next step is to revise ReportCard so that
it uses an array list instead.
Note that ReportCardTester and GradeRecord will not be revised.
- Begin by "stubbing" all the methods of
the ReportCard class; delete all the method contents
so that only curly braces remain for each method;
don't delete the actual method headers/signatures.
Delete the instance fields for ReportCard as well.
- The only instance field needed for this revised
ReportCard class is an array list.
Add this instance field.
- Update the methods so that they operate on that array list instead.