1 / 11

Algorithms

Algorithms. Week 1 Lab. Hobbes. Does everyone have an account on hobbes? Can we log on?. Java. Has everyone had experience programming in Java? Programming assignments in this class will be in Java. Inheritance. Class A { int x; int y; }. Class B extends A { int z; }.

mikasi
Download Presentation

Algorithms

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. Algorithms Week 1 Lab

  2. Hobbes • Does everyone have an account on hobbes? • Can we log on?

  3. Java • Has everyone had experience programming in Java? • Programming assignments in this class will be in Java.

  4. Inheritance Class A { int x; int y; } Class B extends A { int z; } main() { A aInstance; B bInstance; aInstance.x = 2; bInstance.z = 3; bInstance.y = 4; aInstance.z = 6; }

  5. Java Inheritance Stream InputStream OutputStream . . . FileInputStream . . .

  6. Java Interfaces • Multiple inheritance • Like a contract or an agreement • Classes agree to fill all the requirements of the interface. • Classes that do so can share in the interface’s name.

  7. Java Interfaces • Abstract method declarations • public abstract String getName() • Just has a return type and a parameters list. • To implement this part of the interface: • A class must provide a method getName • With no parameters • That returns a String

  8. Our Test Environment • All your programming assignments will use this test environment. • You interact with it by implementing interfaces. • Our environment source code: • SortingAlgorithm sAlg; • Your class file: • public class MySortingAlgorithm implements SortingAlgorithm { ... } • If your class implements SortingAlgorithm properly, this will work properly. • If you implement it improperly, your class won’t compile.

  9. Java Interfaces • Example: Algorithm interface • http://www.seas.gwu.edu/~simhaweb/cs151/hw/ex1/Algorithm.html • This is a superclass for all the interfaces we will use. • Any assignment you turn in needs to have these two methods. • String getName() • void setPropertyExtractor(int algID, PropertyExtractor prop)

  10. Java Interfaces • SortingAlgorithm interface • Methods from Algorithm • String getName() • void setPropertyExtractor(int algID, PropertyExtractor prop) • New methods • int[] createSortIndex(int[] data) • void sortInPlace(int[] data) • int[] createSortIndex(Comparable[] data) • void sortInPlace(Comparable[] data) • You need to have something for each of these methods. • If we tell you not to implement some part of the interface, you still need a stub for that method!! • {} (no body) or {return void;} or something.

  11. Notes • Prof. Simha: • http://www.seas.gwu.edu/~simhaweb/cs151/ • Prof. Youssef: • http://www.seas.gwu.edu/~ayoussef/cs212/

More Related