Files
Java/com/study/demo3/Book.java
2025-11-15 13:30:17 +08:00

58 lines
1.1 KiB
Java

package com.study.demo3;
public class Book {
protected String isbn;
protected String title;
protected boolean available;
public Book() {
this.available = true;
}
public Book(String isbn, String title) {
this.isbn = isbn;
this.title = title;
this.available = true;
}
public Book(String isbn, String title, boolean available) {
this.isbn = isbn;
this.title = title;
this.available = available;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public void returnBook() {
if (!this.available) {
this.available = true;
System.out.println(
this.title + " (ISBN: " + this.isbn + ") has been returned and is now available.");
} else {
System.out.println(this.title + " (ISBN: " + this.isbn + ") is already available.");
}
}
}