Упрощен доступ к методам в классах Task и TodoApp, изменены модификаторы доступа с public на private для улучшения инкапсуляции. Это позволяет защитить внутреннюю логику классов от внешнего вмешательства и улучшает читаемость кода.

This commit is contained in:
KamaSK 2025-05-19 12:24:59 +03:00
parent 45c6e6e3d4
commit a4b250f10b
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,6 @@
package ru.kamask.pet; package ru.kamask.pet;
public class Task { class Task {
private int id; private int id;
private String title; private String title;
private String description; private String description;
@ -12,12 +12,12 @@ public class Task {
this.description = description; this.description = description;
} }
public void printInfo() { void printInfo() {
String stringCompleted = completed ? "[х]" : "[ ]"; String stringCompleted = completed ? "[х]" : "[ ]";
System.out.printf("%-3d | %-20s | %s\n", id, title, stringCompleted); System.out.printf("%-3d | %-20s | %s\n", id, title, stringCompleted);
} }
public void printInfo(boolean full) { void printInfo(boolean full) {
if (!full) { if (!full) {
printInfo(); printInfo();
return; return;
@ -38,15 +38,15 @@ public class Task {
System.out.printf(template, id, stringCompleted, title, description); System.out.printf(template, id, stringCompleted, title, description);
} }
public void toggleCompleted() { void toggleCompleted() {
completed = !completed; completed = !completed;
} }
public int getId() { int getId() {
return id; return id;
} }
public boolean getCompleted() { boolean getCompleted() {
return completed; return completed;
} }
} }

View File

@ -13,7 +13,7 @@ public class TodoApp {
displayMainMenu(); displayMainMenu();
} }
public static int requestIntFromInput(String template, int[] allowedInts) { private static int requestIntFromInput(String template, int[] allowedInts) {
do { do {
System.out.print(template); System.out.print(template);
int input; int input;
@ -35,7 +35,7 @@ public class TodoApp {
} while (true); } while (true);
} }
public static void displayMainMenu() { private static void displayMainMenu() {
while (true) { while (true) {
String menu = """ String menu = """
@ -126,7 +126,7 @@ public class TodoApp {
} }
public static Task getTaskById(int id) { private static Task getTaskById(int id) {
for (int i = 0; i < tasksCounter; i++) { for (int i = 0; i < tasksCounter; i++) {
if (tasks[i].getId() == id) if (tasks[i].getId() == id)
return tasks[i]; return tasks[i];
@ -134,7 +134,7 @@ public class TodoApp {
return null; return null;
} }
public static void displayTask(Task task) { private static void displayTask(Task task) {
task.printInfo(true); task.printInfo(true);
String firstOption = task.getCompleted() ? "[1]Не выполнено" : "[1]Выполнено"; String firstOption = task.getCompleted() ? "[1]Не выполнено" : "[1]Выполнено";
int input = requestIntFromInput(firstOption + " [0]Главное меню\n\nВвод:", int input = requestIntFromInput(firstOption + " [0]Главное меню\n\nВвод:",