In the publishing industry, data arrives in stages. This project models a Book entity that can be registered even if its physical properties (like page count) are not yet finalized. By using Constructor Overloading, the system provides two entry points for data: one for early-stage titles and another for completed manuscripts. This approach ensures that every book in the database is properly initialized, maintaining a high level of data consistency.
- Overloaded Constructors: Provided two distinct ways to instantiate the
Bookclass. - Default Value Assignment: Automatically sets the page count to 0 when only a title is provided.
- State Management: Used the
thiskeyword to correctly map parameters to instance fields. - Architectural Separation: Divided the project into Model, Service, and Reporter layers for clean code.
- Naming Conventions: Followed PascalCase for classes and camelCase for variables/methods.
- Java 8+ (Constructors, Method Overloading, SRP)
- Book: The Model. Defines the structure and initialization rules.
- PublishingService: The Logic. Acts as the "Registrar" for new arrivals.
- BookReporter: The View. Formats and displays book information to the user.
- PublishingApp: The Orchestrator. Executes the registration scenario.
[PUBLISHING]: Registration complete.
Book: A Mysterious Novel, Pages: 0
Book: Traveling through space, Pages: 500
Project Structure:
JavaBasics_Task_236/
├── src/
│ └── com/
│ └── yurii/
│ └── pavlenko/
│ ├── Book.java
│ ├── PublishingService.java
│ ├── BookReporter.java
│ └── PublishingApp.java
└── README.md
Code
package com.yurii.pavlenko;
public class PublishingApp {
public static void main(String[] args) {
PublishingService registrar = new PublishingService();
BookReporter reporter = new BookReporter();
Book mysteriousNovel = registrar.registerTitle("A Mysterious Novel");
Book spaceTravel = registrar.registerFullBook("Traveling through space", 500);
System.out.println("[PUBLISHING]: Registration complete.");
reporter.printReport(mysteriousNovel);
reporter.printReport(spaceTravel);
}
}package com.yurii.pavlenko;
public class Book {
public String bookTitle;
public int pageCount;
public Book(String title) {
this.bookTitle = title;
this.pageCount = 0;
}
public Book(String title, int pages) {
this.bookTitle = title;
this.pageCount = pages;
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT