Question #57082

Hello there. I'm making a class called LibraryRecord, which has 2 constractors. The first one "manages" 6 attributes of an object and they are the following: 1. The title of the book 2. The writer/author 3. The "ISBN"- a serial number. 4. The publisher 5. The year it was published 6. If it's still being published or not. The 1st constructor "accepts" all 6 variables and creates an object Library Record with them. The 2nd constructor only contains the first 5 elements stating the book is still being released. In the program I should include get-methods for every element(all 6 elements), also I should include a set-method with a flag that shows if it's being released or not. And I should do an appropriate use of the method toString. Lastly,I need to make a simple program to test it out.
I get 2 errors when i try to compile the Main Program.
1

Expert's answer

2015-12-22T04:46:51-0500

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";
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS