diff --git a/Plans.java b/Plans.java index 9487088..b6b6ef6 100644 --- a/Plans.java +++ b/Plans.java @@ -2,10 +2,10 @@ import java.util.HashMap; import java.util.Map; public class Plans { - private HashMap plans; + public HashMap plans; public Plans(){ - plans = new HashMap(); + plans = new HashMap<>(); } public Boolean Write(String[] str){ @@ -19,19 +19,7 @@ public class Plans { 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 + " "); - } + ReadDate(entry.getValue()); for (int i = 0; i < entry.getKey().length; i++) { if (entry.getKey()[i] != null) { System.out.print(entry.getKey()[i] + " "); @@ -42,4 +30,20 @@ public class Plans { System.out.println(); } } + + public void ReadDate(MyDate date){ + System.out.print(date.Year + "-"); + if (date.Month < 10){ + System.out.print("0" + date.Month + "-"); + } + else { + System.out.print(date.Month + "-"); + } + if (date.Day < 10){ + System.out.print("0" + date.Day + " "); + } + else { + System.out.print(date.Day + " "); + } + } } diff --git a/Program.java b/Program.java index 914ab09..08e9707 100644 --- a/Program.java +++ b/Program.java @@ -1,8 +1,9 @@ import java.util.Scanner; public class Program { + public static Plans MyPlan; public static void main(String[] args) { - Plans MyPlan = new Plans(); + MyPlan = new Plans(); while (true){ System.out.println("Введите команду:"); Scanner scanner = new Scanner(System.in); @@ -19,6 +20,15 @@ public class Program { case "#read": MyPlan.Read(); break; + case "#statistic": + Statistic st = new Statistic(); + MyDate date = st.GetStatistic(); + if (date != null){ + System.out.print("Самый продуктивный день: "); + MyPlan.ReadDate(date); + } + System.out.println(); + break; default: throw new IllegalStateException("Unexpected value: " + com); } diff --git a/Statistic.java b/Statistic.java new file mode 100644 index 0000000..11479ea --- /dev/null +++ b/Statistic.java @@ -0,0 +1,34 @@ +import java.util.Map; + +public class Statistic { + public int[] count_date; + public MyDate[] dates; + public MyDate _date; + public int count = -1; + public MyDate GetStatistic(){ + if (Program.MyPlan == null){ + return null; + } + count_date = new int[Program.MyPlan.plans.size()]; + dates = new MyDate[Program.MyPlan.plans.size()]; + for (Map.Entry entry : Program.MyPlan.plans.entrySet()){ + if (_date == null || _date.Day != entry.getValue().Day || _date.Month != entry.getValue().Month || + _date.Year != entry.getValue().Year){ + _date = entry.getValue(); + count++; + dates[count] = entry.getValue(); + } + count_date[count]++; + } + + int max = 0, max_i = 0; + for (int i = 0; i <= count; i++){ + if (count_date[i] > max) { + max = count_date[i]; + max_i = i; + } + } + + return dates[max_i]; + } +}