Task
This commit is contained in:
parent
20df01bcb7
commit
f3988c2b2e
16
MyDate.java
Normal file
16
MyDate.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
46
Plans.java
Normal file
46
Plans.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Plans {
|
||||
private HashMap<String[], MyDate> plans;
|
||||
|
||||
public Plans(){
|
||||
plans = new HashMap<String[], MyDate>();
|
||||
}
|
||||
|
||||
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<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 + " ");
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
26
Program.java
Normal file
26
Program.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user