KamaSK ef54b15d2a revert 1a39b1d1eda5635b4e8d1d9b0985cdbc48f42c14
revert Merge pull request 'init/2.0.0' (#20) from init/2.0.0 into main

Reviewed-on: #20
2025-05-25 17:38:06 +03:00

86 lines
1.9 KiB
Java

package ru.kamask.pet;
import java.time.LocalDate;
class Task {
static int taskCount = 0;
enum TaskIdGenerator {
INSTANCE;
private int currentId = 1;
int nextId() {
return currentId++;
}
}
private int id;
private String title;
private String description;
private TaskStatus status;
private LocalDate createdAt;
Task(String title, String description) {
id = TaskIdGenerator.INSTANCE.nextId();
status = TaskStatus.NEW;
createdAt = LocalDate.now();
taskCount++;
this.title = title;
this.description = description;
};
static void printTotalTasksCreated() {
System.out.println("Колличество дел: " + taskCount);
}
int getId() {
return id;
}
String getTitle() {
return title;
}
boolean isCompleted() {
return status == TaskStatus.COMPLETED;
}
void markCompleted() {
status = TaskStatus.COMPLETED;
}
void markInProgress() {
status = TaskStatus.IN_PROGRESS;
}
void markCanceled() {
status = TaskStatus.CANCELLED;
}
TaskStatus getStatus() {
return status;
}
static class TaskPrinter {
static void print(Task task) {
String template = """
──────────────────────────────
Номер: %-3d
Дата создания: %s
Статус: %s
Название: %-20s
------------------------------
%s
""";
;
String stringCompleted = task.status.getColorCode() + task.status.getDescription() + "\u001B[0m";
System.out.printf(template, task.id, task.createdAt, stringCompleted, task.title, task.description);
}
}
}