Menu
Coddy logo textTech

Project Structure

Part of the Object Oriented Programming section of Coddy's C# journey — lesson 62 of 70.

challenge icon

Challenge

Easy

Let's set up the foundation for your Library System project! You'll create the basic file structure that will grow into a complete library management application over the coming lessons.

You'll organize your code across four files, each with a specific responsibility:

  • Book.cs: This file will hold your Book model. For now, create a Book class in the LibrarySystem namespace with three auto-implemented properties: Title (string), Author (string), and IsAvailable (bool, defaulting to true). Add a constructor that takes the title and author as parameters.
  • User.cs: This file will contain your User model. Create a User class in the same namespace with two properties: Name (string) and MemberId (int). Include a constructor that accepts both values.
  • Library.cs: This is where your core logic will live. Create a Library class with a Name property (string) and a constructor to set it. Add a method called GetInfo() that returns a string in the format "{Name} Library System Initialized".
  • Program.cs: Bring everything together here. This is your entry point where you'll create instances of your classes and verify the structure works correctly.

You will receive three inputs:

  • The library name
  • A book entry in the format title|author
  • A user entry in the format name|memberId

Create a Library instance with the given name, a Book with the provided title and author, and a User with the provided name and member ID. Then print three lines:

  1. The result of calling GetInfo() on your library
  2. The book's information in the format Book: {Title} by {Author} - Available: {IsAvailable}
  3. The user's information in the format User: {Name} (ID: {MemberId})

For example, if the inputs are:

City Central
The Great Gatsby|F. Scott Fitzgerald
Alice Johnson|1001

The output should be:

City Central Library System Initialized
Book: The Great Gatsby by F. Scott Fitzgerald - Available: True
User: Alice Johnson (ID: 1001)

This structure follows the Single Responsibility Principle - each file handles one specific concern. In the upcoming lessons, you'll expand these classes with borrowing logic, search functionality, and a full console interface!

Try it yourself

using System;

namespace LibrarySystem
{
    class Program
    {
        public static void Main(string[] args)
        {
            // Read inputs
            string libraryName = Console.ReadLine();
            string bookInput = Console.ReadLine();
            string userInput = Console.ReadLine();

            // Parse book input (format: title|author)
            string[] bookParts = bookInput.Split('|');
            string bookTitle = bookParts[0];
            string bookAuthor = bookParts[1];

            // Parse user input (format: name|memberId)
            string[] userParts = userInput.Split('|');
            string userName = userParts[0];
            int memberId = Convert.ToInt32(userParts[1]);

            // TODO: Create a Library instance with the library name

            // TODO: Create a Book instance with the title and author

            // TODO: Create a User instance with the name and member ID

            // TODO: Print the library info using GetInfo()

            // TODO: Print the book info in format: Book: {Title} by {Author} - Available: {IsAvailable}

            // TODO: Print the user info in format: User: {Name} (ID: {MemberId})
        }
    }
}

All lessons in Object Oriented Programming