1 / 31

Software Development with UML and Java 2 SDJ I2, Spring 2010

Software Development with UML and Java 2 SDJ I2, Spring 2010. Agenda – week 7, 2010 Pakages Looking back Looking forward Packages Interfaces. Download, Install/Setup. Java SE SDK ( http://java.sun.com/javase/downloads ) Java SE SDK - Documentation

axl
Download Presentation

Software Development with UML and Java 2 SDJ I2, Spring 2010

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. Software Development with UML and Java 2SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back • Looking forward • Packages • Interfaces

  2. Download, Install/Setup • Java SE SDK (http://java.sun.com/javase/downloads) • Java SE SDK - Documentation • Setup Environment Variables (e.g. in Windows) • Eclipse IDE (http://www.eclipse.org) • JUDE UML (http://jude.change-vision.com/) • All the above is on the USB stick • Video – How To Install: (http://it-engineering.dk/Course/A09/SDJI1A/Tools/_Video)

  3. Looking back: Java Packages

  4. Java Packages

  5. Package dependencies (class level)

  6. Package dependencies (package level)

  7. Looking forward: What to implement in this course • We will create a lot of collection classes during this course • List containing Strings • array based • dynamic linked based • List with generic type • array based • dynamic linked based • Stack • … • Queue • … • Set • … • SortedSet • …

  8. UML package diagram

  9. Package stringcollection

  10. Package stringcollection (StringList)

  11. Interface IStringList (realization line)

  12. IStringList

  13. Interface for a List of Strings package collection.stringcollection; public interface IStringList { public voidadd(intindex, String element); public voidadd(String element); public void clear(); public booleancontains(String element); public Stringget(intindex); public intindexOf(String element); public booleanisEmpty(); public voidremove(intindex); public voidremove(String element); public void set(intindex, String element); public intsize(); }

  14. Documentation for IStringList (1/8)

  15. Documentation for IStringList (2/8)

  16. Documentation for IStringList (3/8)

  17. Documentation for IStringList (4/8)

  18. Documentation for IStringList (5/8)

  19. Documentation for IStringList (6/8)

  20. Documentation for IStringList (7/8)

  21. Documentation for IStringList (8/8)

  22. UML package diagram (StringListArrayBased)

  23. StringListArrayBased • Example 1:Calling method add(String element)on a StringListArrayBased-object with the parameter element="G"will • Add the element "G"to collection[6] • Increment sizeby one • Example 2: Alternatively, calling add(int index, String element)with the parameters index=3 and element="G" will • Move "F" to index 6, "E" to index 5 and "D" to index 4 • Add the element "G" to index 3 (i.e. collection[3]) • Increment size by one

  24. class StringListArrayBased packagecollection.stringcollection; publicclassStringListArrayBasedimplementsIStringList { private String[] collection; privateint size; privatestaticfinalintDEFAULT_CAPACITY = 20; publicStringListArrayBased(int capacity) { //TODO – implement the constructor } publicStringListArrayBased() { //TODO – implement the constructor } ... // TODO - implement all methods (including method toString()) }

  25. A little help… ... public void add(int index, String element) { if (index > size || index < 0) throw new IndexOutOfBoundsException("index=" + index + " size=" + size); if (size >= collection.length) throw new IllegalStateException(); shiftUp(index); // Makeroom for the element (has to beimplemented) collection[index] = element; size++; } ...

  26. Exercises • Implement the interface IStringList – using an array to store the elements (call the class: StringListArrayBased in package collection.stringcollection) • Find documentation in the SDJI2  javadoc  IStringList, or here: • http://it-engineering.dk/Course/S10/SDJI2A/javadoc/IStringList.html

  27. StringListTest (1/4) import collection.stringcollection.IStringList; public class StringListTest { public static void main(String[] args) { IStringList list = new StringListArrayBased(); list.add("Bob"); list.add("Dee"); printList("BD: ", list); list.add(1,"Carl"); // add in the middle printList("BCD: ", list); list.add(0,"Allan"); // add first printList("ABCD: ", list); list.add(4,"Eric"); // add last printList("ABCDE: ", list);

  28. StringListTest (2/4) printListBackwards("EDCBA: ", list); list.remove(0); // remove first printList("BCDE: ", list); list.remove(list.size()-1); // remove last printList("BCD: ", list); list.remove("Carl"); // remove middle printList("BD: ", list); printListBackwards("DB: ", list); }

  29. StringListTest (3/4) private static void printList(String prompt, IStringList list) { System.out.print(prompt + "{"); for (int i=0; i<list.size(); i++) { System.out.print(list.get(i)); if (i < list.size() - 1) System.out.print(", "); } System.out.println("}"); }

  30. StringListTest (4/4) private static void printListBackwards(String prompt, IStringList list) { System.out.print(prompt + "{"); for (int i=list.size()-1; i>=0; i--) { System.out.print(list.get(i)); if (i > 0) System.out.print(", "); } System.out.println("}"); } }

  31. StringListTest (output) BD: {Bob, Dee} BCD: {Bob, Carl, Dee} ABCD: {Allan, Bob, Carl, Dee} ABCDE: {Allan, Bob, Carl, Dee, Eric} EDCBA: {Eric, Dee, Carl, Bob, Allan} BCDE: {Bob, Carl, Dee, Eric} BCD: {Bob, Carl, Dee} BD: {Bob, Dee} DB: {Dee, Bob}

More Related