Lab 7 of 7: Object-Oriented Application Coding
Method Specification TEMPLATE
|
Method Name: GetCDByCDID() |
Class Name: CDList |
ID: |
|
Contract ID: 1 |
Programmer: Sam |
Date Due: yesterday |
|
Programming Language: C# Visual Basic Smalltalk C# X Java |
||
|
Triggers/Events:
This method is called when the end user selects one CD from the current list of CDs and she or he wants to retrieve the details of the selected CD.
|
||
|
Arguments Received: Data Type: |
Notes: |
|
|
int id
The ID of the selected CD to search for and return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Messages Sent and Arguments Passed: ClassName.MethodName: |
Data Type: |
Notes: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Argument Returned: Data Type: |
Notes: |
|
|
A CD object or null (if no object is found)
Definition of the CD class follows (in Java):
class CD { public CD(int id, String title, String category) { this.CDID = id; this.CDTitle = title; this.CDCategory = category; }
public int CDID; public String CDTitle; public String CDCategory; }
|
||
|
When this method is called on a CDList object, the object must have been populated with a number of CDs to search on by CDID.
For testing purposes, it was decided that the CDList class will be populated with sample data during instantiation. Thus the definition of the CDList class is (in Java):
class CDList { public CD[] CDArray = { new CD (1, "Don't Leave Me", "Pop") , new CD (2, "Hello there", "Jazz") , new CD (3, "Dr. Z", "Classic") };
public CD GetCDByCDID(int id) { // TODO } }
The algorithm of the GetCDByCDID() method is as follows:
Method GetCDByCDID( integer id) Loop over the entire CDArray If a CD is found whose CDID matched the provided id Return this CD End Loop Return null End Method
|
1