Untitled
unknown
plain_text
a year ago
1.8 kB
1
Indexable
Never
/** * A class that maintains information on a book. * This might form part of a larger application such * as a library system, for instance. * * @author (Insert your name here.) * @version (Insert today's date here.) */ class Book { // The fields. private String author; private String title; private int pages; private String refNumber; /** * Set the author and title fields when this object * is constructed. */ public Book(String bookAuthor, String bookTitle, int bookPages) { author = bookAuthor; title = bookTitle; pages = bookPages; refNumber = ""; } public void setRefNumber(String ref) { if(ref.length() >= 3) refNumber = ref; else System.out.println("Error"); } public String getRefNumber() { return refNumber; } // get Author public String getAuthor() { return author; } // get Title public String getTitle() { return title; } // get pages public int getPages() { return pages; } // Print Author public void printAuthor() { System.out.println(author); } //Print Title public void printTitle() { System.out.println(title); } // Print details public void printDetails() { System.out.println("The title of the book is " + title + "."); System.out.println("The author who wrote the book is " + author + "."); System.out.println("There is " + pages + " pages in the book"); if(refNumber.length() > 0) System.out.println(refNumber); else System.out.println("ZZZ"); } }