Presentation is loading. Please wait.

Presentation is loading. Please wait.

Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back.

Similar presentations


Presentation on theme: "Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back."— Presentation transcript:

1 Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back • Looking forward • Packages • Interfaces

2 Page 2 – Spring 2010Steffen Vissing Andersen Download, Install/Setup 1.Java SE SDK (http://java.sun.com/javase/downloads)http://java.sun.com/javase/downloads 2.Java SE SDK - Documentation 3.Setup Environment Variables (e.g. in Windows) 4.Eclipse IDE (http://www.eclipse.org)http://www.eclipse.org 5.JUDE UML (http://jude.change-vision.com/)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 Page 3 – Spring 2010Steffen Vissing Andersen Looking back: Java Packages

4 Page 4 – Spring 2010Steffen Vissing Andersen Java Packages

5 Page 5 – Spring 2010Steffen Vissing Andersen Package dependencies (class level)

6 Page 6 – Spring 2010Steffen Vissing Andersen Package dependencies (package level)

7 Page 7 – Spring 2010Steffen Vissing Andersen 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 Page 8 – Spring 2010Steffen Vissing Andersen UML package diagram

9 Page 9 – Spring 2010Steffen Vissing Andersen Package stringcollection

10 Page 10 – Spring 2010Steffen Vissing Andersen Package stringcollection (StringList)

11 Page 11 – Spring 2010Steffen Vissing Andersen Interface IStringList (realization line)

12 Page 12 – Spring 2010Steffen Vissing Andersen IStringList

13 Page 13 – Spring 2010Steffen Vissing Andersen Interface for a List of Strings package collection.stringcollection; public interface IStringList { public void add(int index, String element); public void add(String element); public void clear(); public boolean contains(String element); public String get(int index); public int indexOf(String element); public boolean isEmpty(); public void remove(int index); public void remove(String element); public void set(int index, String element); public int size(); }

14 Page 14 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (1/8)

15 Page 15 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (2/8)

16 Page 16 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (3/8)

17 Page 17 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (4/8)

18 Page 18 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (5/8)

19 Page 19 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (6/8)

20 Page 20 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (7/8)

21 Page 21 – Spring 2010Steffen Vissing Andersen Documentation for IStringList (8/8)

22 Page 22 – Spring 2010Steffen Vissing Andersen UML package diagram (StringListArrayBased)

23 Page 23 – Spring 2010Steffen Vissing Andersen 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 size by 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 Page 24 – Spring 2010Steffen Vissing Andersen class StringListArrayBased package collection.stringcollection; public class StringListArrayBased implements IStringList { private String[] collection; private int size; private static final int DEFAULT_CAPACITY = 20; public StringListArrayBased(int capacity) { //TODO – implement the constructor } public StringListArrayBased() { //TODO – implement the constructor }... // TODO - implement all methods (including method toString()) }

25 Page 25 – Spring 2010Steffen Vissing Andersen 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); // Make room for the element (has to be implemented) collection[index] = element; size++; }...

26 Page 26 – Spring 2010Steffen Vissing Andersen 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 http://it-engineering.dk/Course/S10/SDJI2A/javadoc/IStringList.html

27 Page 27 – Spring 2010Steffen Vissing Andersen 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 Page 28 – Spring 2010Steffen Vissing Andersen 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 Page 29 – Spring 2010Steffen Vissing Andersen StringListTest (3/4) private static void printList(String prompt, IStringList list) { System.out.print(prompt + "{"); for (int i=0; i { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/7/1995457/slides/slide_29.jpg", "name": "Page 29 – Spring 2010Steffen Vissing Andersen StringListTest (3/4) private static void printList(String prompt, IStringList list) { System.out.print(prompt + { ); for (int i=0; i

30 Page 30 – Spring 2010Steffen Vissing Andersen 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 Page 31 – Spring 2010Steffen Vissing Andersen 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}


Download ppt "Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – week 7, 2010 • Pakages • Looking back."

Similar presentations


Ads by Google