TestLibraryRecord.java
public class TestLibraryRecord {
public static void main(String[] args) {
LibraryRecord r = new LibraryRecord("One story", "NoName", "AADS1234533", "3456233245", "NoName", "2015");
System.out.println(r.toString());
System.out.println("=========================================");
LibraryRecord r1 = new LibraryRecord("One story", "NoName", "AADS1234533", "3456233245", "NoName", "2015", true);
System.out.println(r1.toString());
}
}LibraryRecord.java
public class LibraryRecord {
private String bookTitle;
private String bookAuthor;
private String ISBN;
private String publisher;
private String publisherYear;
private boolean isPublise;
//6 parameters
public LibraryRecord(String bookTitle, String bookAuthor, String ISBN, String serialNumber, String publisher, String publisherYear, boolean isPublise) {
// TODO Auto-generated constructor stub
this.bookTitle = bookTitle;
this.bookAuthor = bookAuthor;
this.ISBN = ISBN;
this.publisher = publisher;
this.publisherYear = publisherYear;
this.isPublise = isPublise;
}
//5 parameters default value boolean is false
public LibraryRecord(String bookTitle, String bookAuthor, String ISBN, String serialNumber, String publisher, String publisherYear) {
// TODO Auto-generated constructor stub
this.bookTitle = bookTitle;
this.bookAuthor = bookAuthor;
this.ISBN = ISBN;
this.publisher = publisher;
this.publisherYear = publisherYear;
}
//getters and setters
public String getBookTitle() {
return bookTitle;
}
public void setBookTitle(String bookTitle) {
this.bookTitle = bookTitle;
}
public String getBookAuthor() {
return bookAuthor;
}
public void setBookAuthor(String bookAuthor) {
this.bookAuthor = bookAuthor;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getPublisherYear() {
return publisherYear;
}
public void setPublisherYear(String publisherYear) {
this.publisherYear = publisherYear;
}
public boolean isPublise() {
return isPublise;
}
public void setPublise(boolean isPublise) {
this.isPublise = isPublise;
}
@Override //new to string method only for objects LibraryRecord
public String toString() {
if (!this.isPublise) {
return this.bookAuthor + " " + this.bookTitle + " " + this.ISBN + " " + this.publisher + " " + this.publisherYear;
} else
return this.bookAuthor + " " + this.bookTitle + " " + this.ISBN + " " + this.publisher + " " + this.publisherYear + " it's still being published";
}
}
Comments