feature/add/array_input_logic #13

Merged
KamaSK merged 2 commits from feature/add/array_input_logic into main 2025-05-19 08:34:27 +03:00
2 changed files with 161 additions and 19 deletions
Showing only changes of commit d36be4f036 - Show all commits

View File

@ -1,23 +1,46 @@
package ru.kamask.pet;
public class Task {
int id;
String title;
String description;
boolean completed;
private int id;
private String title;
private String description;
private boolean completed = false;
Task(String title, String description){
this.id = 0;
Task(int id, String title, String description){
this.id = id;
this.title = title;
this.description = description;
this.completed = false;
}
void printInfo(){
System.out.println(this.title + ": " + (this.completed ? "выполнена." : "в процессе"));
public void printInfo(){
String stringCompleted = completed ? "[х]" : "[ ]";
System.out.printf("%-3d | %s | %-20s\n", id, stringCompleted, title);
}
void markAsCompleted(){
this.completed = true;
public void printInfo(boolean full){
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;
import java.util.Scanner;
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) {
Task t1 = new Task("Первая задача", "Уррааа! Первая задача!");
Task t2 = new Task("Вторя задача", "Ну, вторая уже не первая)))");
t1.printInfo();
t2.printInfo();
t1.markAsCompleted();
t1.printInfo();
t2.printInfo();
mainMenu();
}
public static void mainMenu(){
String menu = """
Введите номер пункта меню
-------------------------
[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() {
}
}