Java Tutorial
Java Project: Library Catalog
A catalog of books with title, author, and year. Search by author and list every match.
What you will build
Store books, print the catalog, then filter by author.
Search by author
Example
record Book(String title, String author, int year) {}
public class Main {
public static void main(String[] args) {
java.util.List books = java.util.List.of(
new Book("Dune", "Herbert", 1965),
new Book("Neuromancer", "Gibson", 1984),
new Book("Destination Void", "Herbert", 1966)
);
String who = "Herbert";
for (Book b : books) {
if (b.author().equals(who)) System.out.println(b.title() + " " + b.year());
}
}
} Practice
- Compile the complete program at
/java/try. - Change one input value and compile again.
- Replace a hardcoded number with
Scannerwhen you want typed input.