vendredi 15 mai 2015
Vererbung Hilfe bei einer Aufgabenstellung
Posted on 16:46 by verona
Hallo zusammen :)
habe im Studium die folgende Aufgabe bekommen:
"Betrachten Sie das unten stehende UML-Klassendiagramm einer einfachen Bibliotheksverwaltung.
Implementieren Sie die darin definierten Klassen genau so, wie vorgegeben. Zur Implementierung
von mehrwertigen Beziehungen und der Methode search in der Klasse Library können Sie die
Klasse List verwenden. Laden Sie sich dafür auch die Klasse ListEntry herunter.
In der Methode search soll die Ausgabe der getDescription()-Methode jedes
LibraryItem-Objektes in der Library daraufhin untersucht werden, ob Sie den übergebenen
String search enthält. Alle LibraryItem-Instanzen, auf die dies zutrifft, sollen in einer
List gesammelt und diese dann zurückgegeben werden.
Schreiben Sie anschließend ein Testprogramm, das automatisiert die Funktionalität der Library
überprüft."
Hier auch noch das UML-Diagramm

Ich tue mich zur Zeit schwer damit das ganze umzusetzen.
Ich weiß leider nicht, ob das was ich bisher geschrieben habe richtig ist und wie ich weitermachen kann.
Es fehlt doch die Verbindung, sprich ich muss doch irgendwie nun meine Instanzen anlegen können, aber ich komm nicht drauf wie. Außerdem verstehe ich nicht ganz was mir die Methode getDescription() zurückliefern soll, hat jemand von euch eine Idee? Vielleicht title, author, director? Wäre auch über einen Link dankbar, der mir bei meinem Problem helfen könnte, ich habe nichts dagegen mich mit einem Thema paar Stunden zu beschäftigen :)
Ich bin jetzt so weit:
Die List und Entry sind diese hier:
Tut mir leid falls das ganze den Rahmen sprengt.
eure Anke :)
habe im Studium die folgende Aufgabe bekommen:
"Betrachten Sie das unten stehende UML-Klassendiagramm einer einfachen Bibliotheksverwaltung.
Implementieren Sie die darin definierten Klassen genau so, wie vorgegeben. Zur Implementierung
von mehrwertigen Beziehungen und der Methode search in der Klasse Library können Sie die
Klasse List verwenden. Laden Sie sich dafür auch die Klasse ListEntry herunter.
In der Methode search soll die Ausgabe der getDescription()-Methode jedes
LibraryItem-Objektes in der Library daraufhin untersucht werden, ob Sie den übergebenen
String search enthält. Alle LibraryItem-Instanzen, auf die dies zutrifft, sollen in einer
List gesammelt und diese dann zurückgegeben werden.
Schreiben Sie anschließend ein Testprogramm, das automatisiert die Funktionalität der Library
überprüft."
Hier auch noch das UML-Diagramm
Ich tue mich zur Zeit schwer damit das ganze umzusetzen.
Ich weiß leider nicht, ob das was ich bisher geschrieben habe richtig ist und wie ich weitermachen kann.
Es fehlt doch die Verbindung, sprich ich muss doch irgendwie nun meine Instanzen anlegen können, aber ich komm nicht drauf wie. Außerdem verstehe ich nicht ganz was mir die Methode getDescription() zurückliefern soll, hat jemand von euch eine Idee? Vielleicht title, author, director? Wäre auch über einen Link dankbar, der mir bei meinem Problem helfen könnte, ich habe nichts dagegen mich mit einem Thema paar Stunden zu beschäftigen :)
Ich bin jetzt so weit:
Java Code:
-
-
public class Library{
-
public Library(){
-
}
-
-
public void addItem(LibraryItem item){
-
}
-
-
public void deleteItem(LibraryItem item ){
-
}
-
-
List items;
-
if (this. = text){
-
items.add(this.);
-
}
-
return items;
-
}
-
}
-
-
abstract class LibraryItem{
-
private boolean isBorrowed;
-
-
public LibraryItem(){
-
}
-
-
public boolean isBorrowed(){
-
return this.isBorrowed;
-
}
-
-
public void setBorrowed(boolean isBorrowed){
-
this.isBorrowed = isBorrowed;
-
}
-
-
return this.;
-
}
-
}
-
-
-
this.title = title;
-
this.author = author;
-
}
-
-
return this.title;
-
}
-
-
return this.author;
-
}
-
-
return this.title + " " + this.author;
-
}
-
}
-
-
class BluRay extends Library{
-
-
this.title = title;
-
this.director = director;
-
}
-
-
return this.title;
-
}
-
-
return this.director;
-
}
-
-
return this.title + " " + this.director;
-
}
-
}
Die List und Entry sind diese hier:
Java Code:
-
-
-
/**
-
* A simple linked list. One may go through this list by {@link #advance()} until
-
* the last position ({@link #endpos()}) is reached. One also may
-
* {@link #delete()} and {@link #insert(Object)} elements. After advancing it is
-
* possible to go back to the beginning by {@link #reset()}.
-
*/
-
-
/**
-
* Reference on the first Entry of this List
-
*/
-
private Entry begin;
-
/**
-
* References before the actual Entry of this List
-
*/
-
private Entry pos;
-
-
/**
-
* Create a new empty List.
-
*/
-
pos = begin = new Entry();
-
}
-
-
/**
-
* Determines if this List is empty or not.
-
*
-
* @return <code>true</code>, if there are no elements in this List
-
*/
-
public boolean empty() {
-
return begin.next == null;
-
}
-
-
/**
-
* Determines if it is possible to {@link #advance()} in this List. Returns
-
* <code>true</code> if the last position of this List has been reached. An
-
* {@link #empty()} List will alway deliver <code>true</code>
-
*
-
* @return <code>true</code> if the last Entry in this List already has been
-
* reached.
-
*/
-
public boolean endpos() { // true, wenn am Ende
-
return pos.next == null;
-
}
-
-
/**
-
* Returns to the beginning of this List.
-
*/
-
public void reset() {
-
pos = begin;
-
}
-
-
/**
-
* Advances one step in this List.
-
*
-
* @throws RuntimeExcpetion
-
* if the last Entry of this List already has been reached.
-
*/
-
public void advance() {
-
if (endpos()) {
-
}
-
pos = pos.next;
-
}
-
-
/**
-
* Returns the actual element of this List.
-
*
-
* @return the actual element
-
*
-
* @throws RuntimeException
-
* if the last Entry of this List already has been reached.
-
*/
-
if (endpos()) {
-
}
-
return pos.next.o;
-
}
-
-
/**
-
* Inserts <code>o</code> in this List. It will be placed before the actual
-
* element. After insertion the inserted element will become the actual
-
* element.
-
*
-
* @param x
-
* the element to be inserted
-
*/
-
Entry newone = new Entry(x, pos.next);
-
-
pos.next = newone;
-
}
-
-
/**
-
* Deletes the actual element of this List. The element after the actual
-
* element will become the new actual element.
-
*
-
* @throws RuntimeExcpetion
-
* if the last Entry of this List already has been reached.
-
*/
-
public void delete() {
-
if (endpos()) {
-
}
-
pos.next = pos.next.next;
-
}
-
}
-
-
-
/**
-
* An Entry holds an Object <code>o</code> and a reference <code>next</code> to
-
* the next Entry such that a linked List of Entry elements is generated.
-
*/
-
class Entry {
-
-
Object o;
-
Entry next;
-
-
Entry() {
-
this(null, null);
-
}
-
-
this(o, null);
-
}
-
-
this.o = o;
-
this.next = e;
-
}
-
-
}
Tut mir leid falls das ganze den Rahmen sprengt.
eure Anke :)
Vererbung Hilfe bei einer Aufgabenstellung
Categories: Vererbung Hilfe bei einer Aufgabenstellung
Inscription à :
Publier les commentaires (Atom)
0 commentaires:
Enregistrer un commentaire