public class Book extends Medium { private final String autor; // Konstruktoren: public Book(String titel, String autor) { this(titel, autor, 0); // rufe anderen Konstruktor in Book mit Preis = 0 (kostenlos) auf } public Book(String titel, String autor, int price) { super(titel, price); // ruft Konstruktor der Oberklasse (Medium) auf; dort wird Attribut titel und preis initialsiert this.autor = autor; // ‾‾‾‾‾ -> verschattet Attribut autor, Zugriff auf verschattete Variable mit this.variablenname } // Getter-Methoden (für alle zusätzlichen Attribute): public String getAutor() { return autor; } // Weitere Methoden (nur für Book): // a) public String toString() { String output = autor + ": " + getTitel() + "(EUR "; int euro = getPreis() / 100; int cent = getPreis() % 100; output += euro; output += ","; if (cent < 10) output += "0"; output += cent; output += ")"; return output; } // d) public boolean hasSameAuthor(Book b) { return autor != null && this.autor.equals(b.autor); } // e) public int authorLetters() { int count = 0; for (int i = 0; i < autor.length(); i++) { char c = autor.charAt(i); if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { // ist Buchstabe count++; } } return count; } public static boolean equals(Book b1, Book b2) { if (b1 == null || b2 == null) return false; return b1.equals(b2); } }