Menu
Coddy logo textTech

Project Overview & UML Design

Part of the Object Oriented Programming section of Coddy's Java journey — lesson 77 of 87.

challenge icon

Challenge

Easy

Let's kick off the Library Management System project by building the foundation—the core entity classes that everything else will depend on. This first challenge focuses on creating well-structured Book and User classes that follow the UML design from the lesson.

You'll organize your code across three files:

  • Book.java: Create the Book class that represents a library book. Each book should have private fields for isbn (String), title (String), author (String), and isAvailable (boolean, defaulting to true). Include a constructor that accepts isbn, title, and author. Provide appropriate getter methods for all fields, and a setter for isAvailable. Add a getDetails() method that returns a formatted string: [isbn] title by author.
  • User.java: Create the User class representing a library member. Each user should have private fields for id (String) and name (String). Include a constructor that accepts both values, and provide getter methods for each field. Add a toString() method that returns: User[id]: name.
  • Main.java: Bring your classes together to demonstrate they work correctly. You'll receive four inputs: a book's ISBN, title, author, and then a user's ID and name.

    Create a Book with the first three inputs and a User with the last two inputs. Print the book's details using getDetails(), then print whether the book is available in the format Available: true or Available: false. Finally, print the user using its toString() method.

You will receive five inputs in order: ISBN (String), title (String), author (String), user ID (String), and user name (String).

For example, with inputs 978-0-13-468599-1, Effective Java, Joshua Bloch, U001, and Alice Smith, your output would be:

[978-0-13-468599-1] Effective Java by Joshua Bloch
Available: true
User[U001]: Alice Smith

These foundational classes will serve as the building blocks for the entire Library Management System. In upcoming lessons, you'll extend them with borrowing functionality, search capabilities, and more!

Try it yourself

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // Read book information
        String isbn = scanner.nextLine();
        String title = scanner.nextLine();
        String author = scanner.nextLine();
        
        // Read user information
        String userId = scanner.nextLine();
        String userName = scanner.nextLine();
        
        // TODO: Create a Book object with isbn, title, and author
        
        // TODO: Create a User object with userId and userName
        
        // TODO: Print the book's details using getDetails()
        
        // TODO: Print whether the book is available (format: "Available: true" or "Available: false")
        
        // TODO: Print the user using toString()
    }
}

All lessons in Object Oriented Programming