Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generic array list and casting C&K s7.7

Similar presentations


Presentation on theme: "Generic array list and casting C&K s7.7"— Presentation transcript:

1 Generic array list and casting C&K s7.7
Intro to Java Week 9 Generic array list and casting C&K s7.7

2 A list class String List Fixed size array of Strings
Attributes list (array) total (so far in list) Methods for add, remove test if OK to add, remove

3 UML class diagram

4 String List method isEmpty
public boolean isEmpty( ){    if (total = = 0) {       return true;    } else {       return false;    } // end if } //end isEmpty

5 Mobile case study - alarm & reminder classes
Alarm has a time (mobile time) and on/off state Reminder is-a alarm plus a message Therefore extend alarm to create reminder class

6 Alarm class

7 Reminder class

8 Generic List Object List Like String List List of any objects
Returned object must be cast to correct class aRecentCall = (PhoneCall) recentCallList.getObject( index );

9 ObjectList class

10 Example usage of Object class
ObjectList reminderlist = new ObjectList(size) for (int index=1; index <= reminderList.getTotal(); index++ ) {    aReminder = (Reminder) reminderList.getObject(index);    System.out.print(aReminder. getAlarmTime().getFormattedTime() );    System.out.println(""+aReminder.getText()); } // end for


Download ppt "Generic array list and casting C&K s7.7"

Similar presentations


Ads by Google