59 lines
2.1 KiB
Java
59 lines
2.1 KiB
Java
|
|
public class Book
|
|
{
|
|
private String title;
|
|
private Person author;
|
|
private int yearOfPublication;
|
|
|
|
public Book (String title, Person author, int yearOfPublication) {
|
|
this.title = title;
|
|
this.author = author;
|
|
this.yearOfPublication = yearOfPublication;
|
|
}
|
|
|
|
public String getInfo() {
|
|
// --> Hier die Lösung zu Aufgabe 1 eintragen. <--
|
|
return "Hier muss was geändert werden.";
|
|
}
|
|
|
|
public int getAge() {
|
|
// --> Hier die Lösung zu Aufgabe 2 eintragen. <--
|
|
return 0;
|
|
}
|
|
|
|
// Diese Methode ist für Euch zum Testen eures Codes gedacht.
|
|
public static void main(String[] args) {
|
|
// Hier werden zunächst zwei Personen erzeugt:
|
|
Person adams = new Person("Douglas", "Adams");
|
|
Person tolkien = new Person("J. R. R.", "Tolkien");
|
|
|
|
// Dann werden zwei Bücher mit den obigen Personen als Autoren erzeugt.
|
|
Book hitchhikersGuide = new Book("The Hitchhiker's Guide to the Galaxy", adams, 1979);
|
|
Book lordOfTheRings = new Book("The Lord of the Rings",tolkien,1954);
|
|
|
|
// Und hier werden die beiden Bücher auf der Konsole ausgegeben.
|
|
System.out.println("--- Test der Methode getInfo() ---");
|
|
System.out.println("- The Hitchhiker's Guide to the Galaxy");
|
|
System.out.println(" Erwartete Ausgabe: Douglas Adams: The Hitchhiker's Guide to the Galaxy (1979)");
|
|
System.out.println(" Deine Ausgabe: " + hitchhikersGuide.getInfo());
|
|
System.out.println();
|
|
|
|
System.out.println("- Lord of the Rings ---");
|
|
System.out.println(" Erwartete Ausgabe: J. R. R. Tolkien: The Lord of the Rings (1954)");
|
|
System.out.println(" Deine Ausgabe: " + lordOfTheRings.getInfo());
|
|
System.out.println();
|
|
|
|
// Zum Schluss wird noch das Berechnen des Alters getestet.
|
|
System.out.println("--- Test der Methode getAge() ---");
|
|
System.out.println("- The Hitchhiker's Guide to the Galaxy");
|
|
System.out.println(" Erwartete Ausgabe: 37");
|
|
System.out.println(" Deine Ausgabe: " + hitchhikersGuide.getAge());
|
|
System.out.println();
|
|
|
|
System.out.println("- Lord of the Rings");
|
|
System.out.println(" Erwartete Ausgabe: 62");
|
|
System.out.println(" Deine Ausgabe: " + lordOfTheRings.getAge());
|
|
System.out.println();
|
|
}
|
|
}
|