Task
This commit is contained in:
parent
c770375b29
commit
eeedeac73d
34
Plans.java
34
Plans.java
@ -2,10 +2,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Plans {
|
||||
private HashMap<String[], MyDate> plans;
|
||||
public HashMap<String[], MyDate> plans;
|
||||
|
||||
public Plans(){
|
||||
plans = new HashMap<String[], MyDate>();
|
||||
plans = new HashMap<>();
|
||||
}
|
||||
|
||||
public Boolean Write(String[] str){
|
||||
@ -19,19 +19,7 @@ public class Plans {
|
||||
|
||||
public void Read(){
|
||||
for (Map.Entry<String[], MyDate> 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 + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
12
Program.java
12
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);
|
||||
}
|
||||
|
34
Statistic.java
Normal file
34
Statistic.java
Normal 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];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user