diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-12-07 19:15:58 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2014-12-07 19:18:03 +0100 |
| commit | 9acea903216dbe371dd7b41cbf23b46a5732bcb4 (patch) | |
| tree | 5a61491ad22e470db8151d2e07f163b011c72d6e /src/de/fhswf/in/inf/java1/aufgabe05/Person.java | |
| parent | 8a53a8fca255e4a84ca0e35dac925a223738b98a (diff) | |
| download | Java1-9acea903216dbe371dd7b41cbf23b46a5732bcb4.tar.gz Java1-9acea903216dbe371dd7b41cbf23b46a5732bcb4.zip | |
Refactored the packagenames fo better sorting
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe05/Person.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe05/Person.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe05/Person.java b/src/de/fhswf/in/inf/java1/aufgabe05/Person.java new file mode 100644 index 0000000..18b619d --- /dev/null +++ b/src/de/fhswf/in/inf/java1/aufgabe05/Person.java @@ -0,0 +1,86 @@ +/** + * + */ +package de.fhswf.in.inf.java1.aufgabe05; + +import java.util.ArrayList; +import java.util.List; + +/** + * A person which can own an account. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public class Person +{ + private String vorname; + + private String nachname; + + private List<Konto> kontenliste = new ArrayList<>(); + + /** + * Creates a person with first and last name. + * + * @param vorname + * First name of the person + * @param nachname + * Last name of the person + */ + public Person(String vorname, String nachname) + { + if (vorname == null) + { + throw new IllegalArgumentException("Vorname can't be null"); + } + if (nachname == null) + { + throw new IllegalArgumentException("Nachname can't be null"); + } + if (vorname.isEmpty()) + { + throw new IllegalArgumentException("Vorname can't be empty"); + } + if (nachname.isEmpty()) + { + throw new IllegalArgumentException("Nachname can't be empty"); + } + this.vorname = vorname; + this.nachname = nachname; + } + + /** + * Just for getting the persons name. + * + * @return Returns the full name of the person + */ + @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); + } + } + +} |
