1 / 9

Recitation 8

Recitation 8. October 15, 2010. Today’s Goals:. Overriding versus overloading a method Implement overloading the equals() on LineSegment class Implement overriding the equals() on LineSegmentCollection class. Extending the Object class.

jonny
Download Presentation

Recitation 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recitation 8 October 15, 2010

  2. Today’s Goals: • Overriding versus overloading a method • Implement overloading the equals() on LineSegment class • Implement overriding the equals() on LineSegmentCollection class

  3. Extending the Object class • All classes extend the Object class either directly or indirectly

  4. Overloading Object equals() public booleanequals(Example otherExample) { if (otherExample != null) { return (this.getX() == otherExample.getX() && this.getY() == otherExample.getY()); } else return false; } equals defined in Example & Object

  5. Overriding Object equals() public boolean equals(Object obj) { if(objinstanceof Example && obj != null) { Example otherObj = (Example)obj; return (this.getX() == otherObj.getX() && this.getY() == otherObj.getY()); } else return false; } equals defined in Example

  6. Overriding & Overloading Object equals()

  7. Recitation Specification • Copy classes and interfaces created last week • OverloadLineSegment equals() method: • Return true if the properties of the LineSegment equals that of the object passed in. • Should have a type of LineSegment, not ALineSegment or AVerticalLineSegment • OverrideALineSegmentCollection equals() method: • Check the size of both collections and match each object for all possible indexes. • Add objects of type ALineSegment and AVerticalLineSegment to the collection. • Call equals on LineSegments and LineSegmentCollections that are the same and different. Output the result to the console.

  8. Setup and Submission • Please follow the instructions on the course website to set up and submit your projects! • Set up your project: • http://www.cs.unc.edu/~dewan/comp114/f10/Recitations/makeproject/ • Submit an assignment: • http://www.cs.unc.edu/~dewan/comp114/f10/Recitations/submit/ • Ask us if you have *ANY* questions on submission

  9. Setting up Object Editor • Recall from lecture: • Jar must be on build path • Import statement necessary! • import bus.uigen.ObjectEditor; • Must call ObjectEditor.edit(yourObject);

More Related