Back to slide -- Keyboard shortcut: 'u'  next  next  Book.java - Den konkrete subklasse Book af Literature.Lecture 8 - slide 9 : 26
Program 2

package microbib;
import java.io.*;
import oopcourse.util.*;

/** A book is characterized by a given author and publisher. */
public class Book extends Literature implements Serializable {

  protected String bookAuthor, bookPublisher;

  /** Contructs a book in terms of a title, an author, a publisher
      and the publication year.  The latter is an integer. */
  public Book(String title, String author, String publisher, int year){
     super (title, year);
     bookAuthor = author; bookPublisher = publisher;}

  /** Returns my author.*/
  public String author(){return bookAuthor;}

  /** Returns my publisher.*/
  public String publisher(){return bookPublisher;}

  protected void printItem(){
      System.out.print(title() + " by " + author() + ", " + year() + 
                       ", published by " + publisher() );
  }

  /** Returns whether I match the search string parameter. */
  public boolean match(String searchString){
    return author().indexOf(searchString) >= 0 ||
           publisher().indexOf(searchString) >= 0 ||
           super.match(searchString);
  }

  /** Return a Book object, the details of which is given by the
     user during simple interaction */
  public static Book prompt()
  {
   String tl = Console.readString("Bog titel: ");
   int yr = Console.readInt("Bog udgivelsesår: ");
   String au = Console.readString("Bogens forfatter: ");
   String forl = Console.readString("Bogen udgivet på hvilket forlag: ");
   return new Book(tl, au, forl, yr);
  }

}