feature/tasks/methods-and-statics #16
@ -1,15 +1,35 @@
|
|||||||
package ru.kamask.pet;
|
package ru.kamask.pet;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
|
private static int nextId;
|
||||||
|
static int taskCount;
|
||||||
|
|
||||||
|
static {
|
||||||
|
taskCount = 0;
|
||||||
|
nextId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private boolean completed = false;
|
private boolean completed = false;
|
||||||
|
private LocalDate createdAt;
|
||||||
|
|
||||||
Task(int id, String title, String description) {
|
Task(String title, String description) {
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
id = ++nextId;
|
||||||
|
createdAt = LocalDate.now();
|
||||||
|
++taskCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printTotalTasksCreated() {
|
||||||
|
System.out.println("Колличество дел: " + taskCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printInfo() {
|
void printInfo() {
|
||||||
@ -27,6 +47,7 @@ class Task {
|
|||||||
|
|
||||||
──────────────────────────────
|
──────────────────────────────
|
||||||
Номер: %-3d
|
Номер: %-3d
|
||||||
|
Дата создания: %s
|
||||||
Статус: %s
|
Статус: %s
|
||||||
Название: %-20s
|
Название: %-20s
|
||||||
------------------------------
|
------------------------------
|
||||||
@ -35,7 +56,7 @@ class Task {
|
|||||||
""";
|
""";
|
||||||
;
|
;
|
||||||
String stringCompleted = completed ? "выполнено" : "не выполнено";
|
String stringCompleted = completed ? "выполнено" : "не выполнено";
|
||||||
System.out.printf(template, id, stringCompleted, title, description);
|
System.out.printf(template, id, createdAt, stringCompleted, title, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleCompleted() {
|
void toggleCompleted() {
|
||||||
|
|||||||
@ -5,8 +5,6 @@ import java.util.Scanner;
|
|||||||
public class TodoApp {
|
public class TodoApp {
|
||||||
|
|
||||||
private static Task[] tasks = new Task[10];
|
private static Task[] tasks = new Task[10];
|
||||||
private static int nextTaskId = 1;
|
|
||||||
private static int tasksCounter = 0;
|
|
||||||
private static Scanner scanner = new Scanner(System.in);
|
private static Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -37,6 +35,7 @@ public class TodoApp {
|
|||||||
|
|
||||||
private static void displayMainMenu() {
|
private static void displayMainMenu() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Task.printTotalTasksCreated();
|
||||||
String menu = """
|
String menu = """
|
||||||
|
|
||||||
┌──────────────────────────┐
|
┌──────────────────────────┐
|
||||||
@ -61,12 +60,11 @@ public class TodoApp {
|
|||||||
|
|
||||||
private static void displayCreateTask() {
|
private static void displayCreateTask() {
|
||||||
|
|
||||||
if (tasksCounter >= 9) {
|
if (Task.taskCount >= 9) {
|
||||||
System.out.println("\nОшибка: Достигнут лимит в 10 дел.\n");
|
System.out.println("\nОшибка: Достигнут лимит в 10 дел.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int id = nextTaskId++;
|
|
||||||
String title;
|
String title;
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
@ -82,13 +80,13 @@ public class TodoApp {
|
|||||||
System.out.print("\nНпишите описание дела: ");
|
System.out.print("\nНпишите описание дела: ");
|
||||||
description = scanner.nextLine().trim();
|
description = scanner.nextLine().trim();
|
||||||
|
|
||||||
var task = new Task(id, title, description);
|
var task = new Task(title, description);
|
||||||
tasks[tasksCounter++] = task;
|
tasks[Task.taskCount - 1] = task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void displayTasks() {
|
private static void displayTasks() {
|
||||||
|
|
||||||
if (tasksCounter < 1) {
|
if (Task.taskCount == 0) {
|
||||||
int input = requestIntFromInput("""
|
int input = requestIntFromInput("""
|
||||||
|
|
||||||
Список дел пуст.
|
Список дел пуст.
|
||||||
@ -105,16 +103,16 @@ public class TodoApp {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] variantsInput = new int[tasksCounter + 1];
|
int[] variantsInput = new int[Task.taskCount + 1];
|
||||||
System.out.println("""
|
System.out.println("""
|
||||||
Список дел:
|
Список дел:
|
||||||
|
|
||||||
""");
|
""");
|
||||||
for (int i = 0; i < tasksCounter; i++) {
|
for (int i = 0; i < Task.taskCount; i++) {
|
||||||
tasks[i].printInfo();
|
tasks[i].printInfo();
|
||||||
variantsInput[i] = tasks[i].getId();
|
variantsInput[i] = tasks[i].getId();
|
||||||
}
|
}
|
||||||
variantsInput[tasksCounter] = 0;
|
variantsInput[Task.taskCount] = 0;
|
||||||
int input = requestIntFromInput("""
|
int input = requestIntFromInput("""
|
||||||
|
|
||||||
Введите номер дела или 0 для возврата в меню:""", variantsInput);
|
Введите номер дела или 0 для возврата в меню:""", variantsInput);
|
||||||
@ -127,7 +125,7 @@ public class TodoApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Task getTaskById(int id) {
|
private static Task getTaskById(int id) {
|
||||||
for (int i = 0; i < tasksCounter; i++) {
|
for (int i = 0; i < Task.taskCount; i++) {
|
||||||
if (tasks[i].getId() == id)
|
if (tasks[i].getId() == id)
|
||||||
return tasks[i];
|
return tasks[i];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user