# Probleme mit der Aufgabe eine Bibliothek in Java zu erstellen



## joey21 (19. Januar 2008)

Hallo ich übe zurzeit anhand von aufgaben von der Uni mein programmieren in Java, jedoch  habe ich noch einige Probleme, könnte sich viell jemand mein Quellcode anschauen zu der aufgabe (siehe unten) und mir sagen was der fehler ist bzw eine lösung geben?
lg joey


A Basic Library

Your task is to write a basic library. Your library must be able to accept new books to be added.

This task should help you with the following basic Java programming questions:

   1.

      How are classes combined to form a working program?
   2.

      Where does a Java program start?
   3.

      What are Arrays and how can I use them?
   4.

      What does Overriding a method mean?

The following three classes must be implemented:

   1.

      Buch ... represents a book in your library.
   2.

      Bibliothek ... represents the library itself.
   3.

      HalloBibliothek ... starting class which contains the main() method; entry point of your program.

1. The class Buch ("book")

This class represents books.

On creation of an object of this type Buch (in the Constructor) the following line must be printed:

'Buch titel erzeugt.'

The title of the book is passed to the contructor as parameter, and stored inside an attribute to initialize the book object with this title.

To make it easier to access the title, the toString() method must be overriden.

It returns a String reperesentation of an object, in our case it should be the books' title.

After overriding, one can write the following to print the title:

// Create a book called 'Java fuer Dummies' and store it to the variable buch

Buch buch = new Buch("Java fuer Dummys");

// print title of this book

System.out.println(buch);

The variable buch, containing a reference to an object of type Buch, can directly be accessed from within the println() statement.

Implicitly, Java calls the toString() method. If you don't overwrite the toString() method, a default toString() method is executed and a cryptic ID is returned.

To make the code above return the proper book title, you must override the method toString() in your class Buch.
2. The Class Bibliothek ("library")

This class represents libraries.

On creation of an object of this type, the following message must be printed:

'Hallo, ich bin eine Bibliothek, die 10 Buecher aufnehmen kann!'

It should be possible to add books (ie. objects of type Buch) to this library using the method aufnehmen().

If this method is called, the following message must be printed:

'Ich habe das Buch titel aufgenommen!'

The book objects are passed as a parameter to this function and must be stored inside the library.



Hint

For now, you should use an attribute of type Array. This data structure can hold a certain amount of objects.

You have to pay attention to the limits of this array.

Bsp.: int[] feld = new int[20];

This array can only store 20 values of type int (Integer, whole numbers).

You can access values using the index, beginning with 0.

For example, to write the value 7 to the first array entry and 3 to the last, use:

feld[0] = 7;

bzw.

feld[19] = 3;
3. The class HalloBibliothek

Every program requires an entry point where execution begins. In Java, this is the main() method.

In our case, the main() method should be written in the class HalloBibliothek.

Constructing a main() method:

public static void main(String[] args) {

...

}

The main method must solve the following tasks:

   1.

      Create an object of type Bibliothek and save it to a variable called bibo.
   2.

      Create an object of type Buch and save it to a variable called buch1.
   3.

      Create an object of type Buch and save it to a variable called buch2.
   4.

      Add the two book objects buch1 and buch2 to the library using the method aufnehmen() of your object bibo.

4. Example Output

Your program should return the following output:

Hallo, ich bin eine Bibliothek, die 10 Buecher aufnehmen kann!

Buch UML erzeugt.

Buch Java2 erzeugt.

Ich habe das Buch UML aufgenommen!

Ich habe das Buch Java2 aufgenommen!
5. Submission


----------



## zeja (20. Januar 2008)

Du scheinst ja von Java bisher noch gar nichts gelernt zu haben. Bevor du die Aufgabe lösen kannst solltest du dir erstmal ein wenig was durchlesen:
http://www.galileocomputing.de/openbook/javainsel7/

Die Kapitel 2-4 sollten dir weiterhelfen.


----------



## procurve (20. Januar 2008)

Das klingt verdammt nach einer Aufgabe aus einem Aufgabenzettel bei mir an der Uni.


----------

