diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-10-29 13:21:44 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-10-29 13:21:44 +0100 |
| commit | cbfcc3df88e229a81da783e258a0b8860404fe1a (patch) | |
| tree | 628595c0fd5d2f6d8ee36bfc6dc203bb9796ecf9 /src/de/fhswf/in/inf/java1/aufgabe5/Person.java | |
| parent | c8243c6987618ed97c0e89459c6dbc900ffe063e (diff) | |
| download | Java1-cbfcc3df88e229a81da783e258a0b8860404fe1a.tar.gz Java1-cbfcc3df88e229a81da783e258a0b8860404fe1a.zip | |
Assignment No.2 after correction
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe5/Person.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe5/Person.java | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe5/Person.java b/src/de/fhswf/in/inf/java1/aufgabe5/Person.java index bfe19d0..15de304 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe5/Person.java +++ b/src/de/fhswf/in/inf/java1/aufgabe5/Person.java @@ -3,6 +3,9 @@ */ package de.fhswf.in.inf.java1.aufgabe5; +import java.util.ArrayList; +import java.util.List; + /** * A person which can own an account. * @@ -15,6 +18,8 @@ public class Person private String nachname; + private List<Konto> kontenliste = new ArrayList<>(); + /** * Creates a person with first and last name. * @@ -33,11 +38,11 @@ public class Person { throw new IllegalArgumentException("Nachname can't be null"); } - if (vorname == "") + if (vorname.isEmpty()) { throw new IllegalArgumentException("Vorname can't be empty"); } - if (nachname == "") + if (nachname.isEmpty()) { throw new IllegalArgumentException("Nachname can't be empty"); } @@ -50,9 +55,32 @@ public class Person * * @return Returns the full name of the person */ - public String getName() + @Override + public String toString() { return vorname + " " + nachname; } + /** + * For adding the back reference to the Konto. + * + * @param konto + * Konto that will be added to the person. + */ + public void addKonto(Konto konto) + { + if (konto == null) + { + throw new IllegalArgumentException("Konto can't be empty"); + } + if (konto.getBesitzer() != this) + { + throw new IllegalArgumentException("Person must be owner of Konto"); + } + if (!kontenliste.contains(konto)) + { + kontenliste.add(konto); + } + } + } |
