This commit is contained in:
Anitonchik 2024-06-07 16:21:20 +04:00
parent c770375b29
commit eeedeac73d
3 changed files with 64 additions and 16 deletions

View File

@ -2,10 +2,10 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Plans { public class Plans {
private HashMap<String[], MyDate> plans; public HashMap<String[], MyDate> plans;
public Plans(){ public Plans(){
plans = new HashMap<String[], MyDate>(); plans = new HashMap<>();
} }
public Boolean Write(String[] str){ public Boolean Write(String[] str){
@ -19,19 +19,7 @@ public class Plans {
public void Read(){ public void Read(){
for (Map.Entry<String[], MyDate> entry : plans.entrySet()){ for (Map.Entry<String[], MyDate> entry : plans.entrySet()){
System.out.print(entry.getValue().Year + "-"); ReadDate(entry.getValue());
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++) { for (int i = 0; i < entry.getKey().length; i++) {
if (entry.getKey()[i] != null) { if (entry.getKey()[i] != null) {
System.out.print(entry.getKey()[i] + " "); System.out.print(entry.getKey()[i] + " ");
@ -42,4 +30,20 @@ public class Plans {
System.out.println(); 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 + " ");
}
}
} }

View File

@ -1,8 +1,9 @@
import java.util.Scanner; import java.util.Scanner;
public class Program { public class Program {
public static Plans MyPlan;
public static void main(String[] args) { public static void main(String[] args) {
Plans MyPlan = new Plans(); MyPlan = new Plans();
while (true){ while (true){
System.out.println("Введите команду:"); System.out.println("Введите команду:");
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
@ -19,6 +20,15 @@ public class Program {
case "#read": case "#read":
MyPlan.Read(); MyPlan.Read();
break; 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: default:
throw new IllegalStateException("Unexpected value: " + com); throw new IllegalStateException("Unexpected value: " + com);
} }

34
Statistic.java Normal file
View File

@ -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<String[], MyDate> 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];
}
}