Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 0bafaab

Browse files
committed
Лабораторная 11
1 parent 441a969 commit 0bafaab

File tree

3 files changed

+88
-14
lines changed

3 files changed

+88
-14
lines changed

students/23K0130/23K0130-p11/src/main/java/ru/mirea/practice/s23k0130/task1/Developer.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ru.mirea.practice.s23k0130.task1;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
import java.util.Scanner;
7+
8+
public final class Main {
9+
10+
private Main() {
11+
12+
}
13+
14+
public static void main(String[] args) {
15+
16+
try (Scanner scanner = new Scanner(System.in)) {
17+
18+
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
19+
dateFormat.setLenient(false);
20+
21+
System.out.println("Введите фамилию");
22+
String lastName = scanner.nextLine();
23+
24+
System.out.println("Введите дату и время в формате dd.MM.yyyy HH:mm:ss");
25+
String userInput = scanner.nextLine();
26+
27+
try {
28+
Date userDate = dateFormat.parse(userInput);
29+
Date currentDate = new Date();
30+
System.out.println("Фамилия разработчика: " + lastName);
31+
System.out.println("Введённая дата и время: " + dateFormat.format(userDate));
32+
System.out.println("Текущая дата и время: " + dateFormat.format(currentDate));
33+
34+
} catch (ParseException e) {
35+
System.out.println("Ошибка: Неверный ввод.");
36+
} finally {
37+
scanner.close();
38+
}
39+
}
40+
}
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ru.mirea.practice.s23k0130.task2;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
import java.util.Scanner;
7+
8+
public final class Main {
9+
10+
private Main() {
11+
12+
}
13+
14+
public static void main(String[] args) {
15+
16+
try (Scanner scanner = new Scanner(System.in)) {
17+
18+
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
19+
dateFormat.setLenient(false);
20+
21+
System.out.println("Введите дату и время в формате dd.MM.yyyy HH:mm:ss");
22+
String userInput = scanner.nextLine();
23+
24+
try {
25+
Date userDate = dateFormat.parse(userInput);
26+
27+
Date currentDate = new Date();
28+
29+
System.out.println("Введённая дата и время: " + dateFormat.format(userDate));
30+
System.out.println("Текущая дата и время: " + dateFormat.format(currentDate));
31+
32+
if (userDate.before(currentDate)) {
33+
System.out.println("Введённая дата и время раньше текущей системной даты.");
34+
} else if (userDate.after(currentDate)) {
35+
System.out.println("Введённая дата и время позже текущей системной даты.");
36+
} else {
37+
System.out.println("Введённая дата и время совпадают с текущей системной датой.");
38+
}
39+
40+
} catch (ParseException e) {
41+
System.out.println("Ошибка: Неверный ввод.");
42+
} finally {
43+
scanner.close();
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)