/** * 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; private int borrowed; /** * 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 = ""; borrowed = 0; } public String getAuthor() { return author; } public String getTitle() { return title; } public int getPages() { return pages; } public void setRefNumber(String ref) { refnumber = ref; if ( refnumber.length() < 3) { refnumber = ""; System.out.println("ERROR REFERENCE MUST BE ATLEAST 3 CHARACTERS"); } else {refnumber = ref ; } } public String getRefnumber() { return refnumber; } public int getBorrowed() { return borrowed; } public int increaseBorrowed() { borrowed = borrowed + 1; return borrowed; } public void printAuthor() { System.out.println("Author - "+ author +" "); } public void printTitle() { System.out.println("Title - "+ title +" "); } public void printPages() { System.out.println("Pages - "+ pages +" "); } public void printDetails() { if( refnumber.length() > 0) { System.out.println("Title - "+ title +", Author - "+ author +", Pages - "+ pages +", Reference Number - " + refnumber +". Number of times borrowed " + borrowed +"."); } else { System.out.println("Title - "+ title +", Author - "+ author +", Pages -"+ pages +". ZZZ. Number of times borrowed " + borrowed +"."); } } }