/
sobaka1
/
solarlab_test
Обзор
Документация
Войти
/
sobaka1
/
solarlab_test
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
birthdayapp.java
92 строки
3 KB
sobaka1
initial project file
05 фев 2026, 20:22
Верифицирован
05 фев 2026, 20:22
c51309e
Код
Авторство
О чём код?
import java.io.*; import java.util.*; import java.time.LocalDate; import java.time.format.DateTimeFormatter; class Birthday implements Serializable { public String name; public LocalDate date; public Birthday(String name, LocalDate date) { this.name = name; this.date = date; } @Override public String toString() { return name + " (" + date.getDayOfMonth() + "." + date.getMonthValue() + "." + date.getYear() + ")"; } } public class BirthdayApp { public static void main(String[] args) throws Exception { ArrayList<Birthday> list = new ArrayList<>(); File file = new File("data.bin"); DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd.MM.yyyy"); if (file.exists()) { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); list = (ArrayList<Birthday>) ois.readObject(); ois.close(); } LocalDate today = LocalDate.now(); System.out.println("=== STATUS ==="); for (Birthday b : list) { LocalDate next = b.date.withYear(today.getYear()); if (next.isBefore(today)) { next = next.plusYears(1); } if (next.equals(today)) { System.out.println("TODAY: " + b.name); } else if (next.isBefore(today.plusDays(7))) { System.out.println("SOON: " + b.name + " (" + b.date.getDayOfMonth() + "." + b.date.getMonthValue() + ")"); } } System.out.println("=============="); Scanner sc = new Scanner(System.in); while (true) { System.out.println("\n1. Show All"); System.out.println("2. Add"); System.out.println("3. Delete"); System.out.println("4. Exit"); System.out.print("Choice: "); String cmd = sc.nextLine(); if (cmd.equals("1")) { for (int i = 0; i < list.size(); i++) { System.out.println(i + ". " + list.get(i)); } } else if (cmd.equals("2")) { try { System.out.print("Name: "); String n = sc.nextLine(); System.out.print("Date (dd.mm.yyyy): "); String d = sc.nextLine(); list.add(new Birthday(n, LocalDate.parse(d, fmt))); } catch (Exception e) { System.out.println("Error!"); } } else if (cmd.equals("3")) { try { System.out.print("Index: "); int idx = Integer.parseInt(sc.nextLine()); list.remove(idx); } catch (Exception e) { System.out.println("Error!"); } } else if (cmd.equals("4")) { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(list); oos.close(); break; } } } }