From f3988c2b2e1dbf3a3c5bcadb5d9548551350ce77 Mon Sep 17 00:00:00 2001 From: Anitonchik Date: Fri, 7 Jun 2024 11:25:39 +0400 Subject: [PATCH] Task --- MyDate.java | 16 ++++++++++++++++ Plans.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Program.java | 26 ++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 MyDate.java create mode 100644 Plans.java create mode 100644 Program.java diff --git a/MyDate.java b/MyDate.java new file mode 100644 index 0000000..d5b517e --- /dev/null +++ b/MyDate.java @@ -0,0 +1,16 @@ +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +public class MyDate { + Calendar calendar = Calendar.getInstance(); + public int Year; + public int Month; + public int Day; + public MyDate(){ + Year = calendar.get(Calendar.YEAR); + Month = calendar.get(Calendar.MONTH); + Day = calendar.get(Calendar.DAY_OF_MONTH); + } +} diff --git a/Plans.java b/Plans.java new file mode 100644 index 0000000..2507255 --- /dev/null +++ b/Plans.java @@ -0,0 +1,46 @@ +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class Plans { + private HashMap plans; + + public Plans(){ + plans = new HashMap(); + } + + public Boolean Write(String[] str){ + if (str == null){ + return false; + } + MyDate myDate = new MyDate(); + plans.put(str, myDate); + return true; + } + + public void Read(){ + for (Map.Entry entry : plans.entrySet()){ + System.out.print(entry.getValue().Year + "-"); + if (entry.getValue().Month < 10){ + System.out.print("0" + entry.getValue().Month + "-"); + } + else { + System.out.print(entry.getValue().Month + "-"); + } + if (entry.getValue().Day < 10){ + System.out.print("0" + entry.getValue().Day + " "); + } + else { + System.out.print(entry.getValue().Day + " "); + } + for (int i = 0; i < entry.getKey().length; i++) { + if (entry.getKey()[i] != null) { + System.out.print(entry.getKey()[i] + " "); + } + else + break; + } + System.out.println(); + } + } +} diff --git a/Program.java b/Program.java new file mode 100644 index 0000000..7b6a4ae --- /dev/null +++ b/Program.java @@ -0,0 +1,26 @@ +import java.util.Objects; +import java.util.Scanner; +public class Program { + public static void main(String[] args) { + + Plans MyPlan = new Plans(); + while (true){ + System.out.println("Введите команду:"); + Scanner scanner = new Scanner(System.in); + String com = scanner.nextLine(); + switch (com){ + case "#write": + System.out.println("Введите ваши планы на сегодня: "); + String write = scanner.nextLine(); + String[] words = write.split(" "); + MyPlan.Write(words); + break; + case "#read": + MyPlan.Read(); + break; + default: + throw new IllegalStateException("Unexpected value: " + com); + } + } + } +}