-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.java
More file actions
42 lines (32 loc) · 1.38 KB
/
Runner.java
File metadata and controls
42 lines (32 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package book;
import java.util.ArrayList;
import java.util.List;
public class Runner {
public static void main (String[] args) {
// Create an ArrayList of Book objects
List<Book> bookList = new ArrayList<>();
// Add books to the ArrayList
bookList.add(new Book("Moby Dick", "Herman Melville", true));
bookList.add(new Book("The Adventures of Sherlock Holmes", "Sir Arthur Conan Doyle", false));
bookList.add(new Book("Pride and Prejudice", "Jane Austen", true));
bookList.add(new Book("The Catcher in the Rye", "J.D. Salinger", false));
// Iterate through the ArrayList and display book information
for (Book book : bookList) {
if (book.isBorrowed()) {
System.out.println("Book borrowed.");
} else {
System.out.println("Book is not borrowed.");
}
System.out.println("Title: " + book.getTitle());
System.out.println("Author: " + book.getAuthor());
System.out.println("Book: " + book.toString());
boolean returned = book.giveBack();
if (returned) {
System.out.println("Book returned.");
} else {
System.out.println("Book is available for borrowing.");
}
System.out.println(); // Add a blank line for separation
}
}
}