Промежуточный коммит

This commit is contained in:
KamaSK 2025-05-17 21:21:57 +03:00
parent 768d4df2ed
commit d36be4f036
2 changed files with 161 additions and 19 deletions

View File

@ -1,23 +1,46 @@
package ru.kamask.pet; package ru.kamask.pet;
public class Task { public class Task {
int id; private int id;
String title; private String title;
String description; private String description;
boolean completed; private boolean completed = false;
Task(String title, String description){ Task(int id, String title, String description){
this.id = 0; this.id = id;
this.title = title; this.title = title;
this.description = description; this.description = description;
this.completed = false;
} }
void printInfo(){ public void printInfo(){
System.out.println(this.title + ": " + (this.completed ? "выполнена." : "в процессе")); String stringCompleted = completed ? "[х]" : "[ ]";
System.out.printf("%-3d | %s | %-20s\n", id, stringCompleted, title);
} }
void markAsCompleted(){ public void printInfo(boolean full){
this.completed = true; if (!full){
printInfo();
return;
}
String template = """
Номер: %-3d
Статус: %s
Название: %-20s
------------------------------
%s
""";;
String stringCompleted = completed ? "в процессе" : "завершена";
System.out.printf(template, id, stringCompleted, title, description);
}
public void markAsCompleted(){
completed = true;
}
public int getId(){
return id;
} }
} }

View File

@ -1,13 +1,132 @@
package ru.kamask.pet; package ru.kamask.pet;
import java.util.Scanner;
public class TodoApp { public class TodoApp {
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);
public static void main(String[] args) { public static void main(String[] args) {
Task t1 = new Task("Первая задача", "Уррааа! Первая задача!"); mainMenu();
Task t2 = new Task("Вторя задача", "Ну, вторая уже не первая)))"); }
t1.printInfo();
t2.printInfo(); public static void mainMenu(){
t1.markAsCompleted(); String menu = """
t1.printInfo();
t2.printInfo(); Введите номер пункта меню
-------------------------
[1] Добавить дело
[2] Список дел
[0] Выйти из программы
""";
while (true) {
System.err.printf(menu);
switch (scanner.nextLine().trim()) {
case "1" -> createTask();
case "2" -> listTasks();
case "0" -> {
scanner.close();
System.exit(0);
}
default -> {
System.out.println("Неизвестная команда. Используйте цифры.");
}
}
}
}
private static void createTask() {
if (tasksCounter >= 9) {
System.out.println("Ошибка: Достигнут лимит в 10 дел.");
return;
}
int id = nextTaskId++;
String title;
System.out.println("Нпишите название дела (320 символов)");
while (true) {
title = scanner.nextLine().trim();
if (title.length() >= 3 && title.length() <= 20)
break;
System.out.println("Ошибка: Название должно содержать от 3 до 20 символов. Попробуйте снова.");
}
System.out.println("Нпишите описание дела");
String description = scanner.nextLine().trim();
var task = new Task(id, title, description);
tasks[tasksCounter++] = task;
}
private static void listTasks() {
if(tasksCounter < 1){
System.out.println("""
Список дел пуст.
[1] Добавить дело
[0] Выйти из программы
""");
while (true) {
String input = scanner.nextLine().trim();
if(input.equals("1")) createTask();
if(input.equals("0")) System.exit(0);
System.out.println("Неизвестная команда. Используйте цифры.");
}
}
System.out.println("\nСписок дел:\n");
for (int i = 0; i < tasksCounter; i++) {
tasks[i].printInfo();
}
System.out.println("Введите номер дела, или 0 для возврата в главное меню:\n");
while (true) {
String input = scanner.nextLine().trim();
if(input.equals("0")) return;
if(input.matches("\\d+")){
/*
*
*
*/
}
System.out.println("Неизвестная команда. Используйте цифры.");
}
}
public static Task getTaskById(int id) {
for (int i = 0; i < tasksCounter; i++) {
if(tasks[i].getId() == id) return tasks[i];
}
return null;
}
public static void taskMenu(Task task){
}
public static void requestInput() {
} }
} }