• No results found

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

N/A
N/A
Protected

Academic year: 2021

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

Copied!
31
0
0

Loading.... (view fulltext now)

Full text

(1)

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 2010 Steffen Vissing Andersen

Download, Install/Setup

1.

Java SE SDK (

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

)

5.

JUDE UML (

http://jude.change-vision.com/

)

All the above is on the USB stick

Video – How To Install:

(3)
(4)

Page 4 – Spring 2010 Steffen Vissing Andersen

(5)
(6)

Page 6 – Spring 2010 Steffen Vissing Andersen

(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)

Page 8 – Spring 2010 Steffen Vissing Andersen

(9)
(10)

Page 10 – Spring 2010 Steffen Vissing Andersen

(11)
(12)

Page 12 – Spring 2010 Steffen Vissing Andersen

(13)

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);

(14)

Page 14 – Spring 2010 Steffen Vissing Andersen

(15)
(16)

Page 16 – Spring 2010 Steffen Vissing Andersen

(17)
(18)

Page 18 – Spring 2010 Steffen Vissing Andersen

(19)
(20)

Page 20 – Spring 2010 Steffen Vissing Andersen

(21)
(22)

Page 22 – Spring 2010 Steffen Vissing Andersen

(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 size by one

 Example 2: Alternatively, calling add(int index, String element)

(24)

Page 24 – Spring 2010 Steffen 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)

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 2010 Steffen 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/SDJI2B/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);

(28)

Page 28 – Spring 2010 Steffen 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)

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)

Page 30 – Spring 2010 Steffen 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)

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}

References

Related documents

At this stage, the influence of the unbalances and the grounding location in bipolar HVDC grids on fault behavior and protection systems are not fully understood. This paper

As Halley demonstrates in “Rape at Rome: Feminist Interventions in the Criminalization of Sex-Related Violence in Positive International Criminal Law” (2008), feminists advanced

[r]

Zell: Artificial Intelligence (after Russel/Norvig, 3rd Ed.) 58 (b) The recursion unwinds and the best leaf value of the forgotten subtree (417) is backed up to Rimnicu Vilcea;

Commercial Financial Technical Execution Engineering &amp; Procurement Construction &amp; Startup Project Execution Planning Front-End Engineering Design Strategic Project

Bicolored or uniformly dark, with microsculpture mesh pattern slightly transverse, sculpticells slightly wider than long (Fig. 5C-D) in dorsal aspect slender, shaft subsinuate,

Climate change has the power to affect many ecological processes, but the most obvious changes ap- pear in the form of melting sea ice, sea level rise, changes in oceanic

SANDVIK CNMA 12 04 08 H1P (uncoated carbide) inserts were used throughout. conventional emulsified mineral oil based flood cooling system was utilized. The three main