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

Commit 294cee4

Browse files
committed
Лабораторная№11-15
1 parent d9aeb9e commit 294cee4

File tree

35 files changed

+1188
-1
lines changed

35 files changed

+1188
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p12</artifactId>
12+
<description>12 практическая</description>
13+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p11</artifactId>
12+
<description>11 практическая</description>
13+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.util.Date;
4+
5+
public final class Fam {
6+
private Fam() {}
7+
8+
public static void main(String[] args) {
9+
String fam = "Самохин";
10+
Date datPoluch = new Date();
11+
12+
System.out.println("Разработчик: " + fam);
13+
System.out.println("Дата и время получения задания: " + datPoluch);
14+
15+
Date datSdacha = new Date();
16+
System.out.println("Дата и время сдачи задания: " + datSdacha);
17+
}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.Date;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
import java.util.Scanner;
7+
8+
public final class DateCompare {
9+
private DateCompare() {}
10+
11+
public static void main(String[] args) {
12+
try (Scanner scn = new Scanner(System.in)) {
13+
System.out.print("Введите дату в формате ГГГГ-ММ-ДД: ");
14+
String userDateStr = scn.nextLine();
15+
16+
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
17+
try {
18+
Date userDate = fmt.parse(userDateStr);
19+
Date currDate = new Date();
20+
21+
if (userDate.equals(currDate)) {
22+
System.out.println("Даты совпадают");
23+
} else if (userDate.before(currDate)) {
24+
System.out.println("Введённая дата раньше текущей");
25+
} else {
26+
System.out.println("Введённая дата позже текущей");
27+
}
28+
} catch (ParseException e) {
29+
System.out.println("Неверный формат даты");
30+
}
31+
}
32+
}
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
5+
6+
public class Student {
7+
private String firstName;
8+
private String lastName;
9+
private String specialty;
10+
private int course;
11+
private String group;
12+
private Date birthDate;
13+
14+
public Student(String firstName, String lastName, String specialty, int course, String group, Date birthDate) {
15+
this.firstName = firstName;
16+
this.lastName = lastName;
17+
this.specialty = specialty;
18+
this.course = course;
19+
this.group = group;
20+
this.birthDate = birthDate;
21+
}
22+
23+
public Date getBirthDate() {
24+
return birthDate;
25+
}
26+
27+
public void setBirthDate(Date birthDate) {
28+
this.birthDate = birthDate;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
SimpleDateFormat shortFmt = new SimpleDateFormat("dd.MM.yy");
34+
SimpleDateFormat mediumFmt = new SimpleDateFormat("dd MMM yyyy");
35+
SimpleDateFormat longFmt = new SimpleDateFormat("EEEE, dd MMMM yyyy");
36+
37+
return "Имя: " + firstName + " " + lastName + "\n"
38+
+ "Специальность: " + specialty + "\n"
39+
+ "Курс: " + course + "\n"
40+
+ "Группа: " + group + "\n"
41+
+ "Дата рождения (короткий формат): "
42+
+ shortFmt.format(birthDate) + "\n"
43+
+ "Дата рождения (средний формат): "
44+
+ mediumFmt.format(birthDate) + "\n"
45+
+ "Дата рождения (полный формат): "
46+
+ longFmt.format(birthDate);
47+
}
48+
49+
public static void main(String[] args) {
50+
Date birth = new Date(05, 6, 11);
51+
Student stud = new Student("Михаил", "Самохин", "Авт", 2, "КАБО-02-23", birth);
52+
System.out.println(stud);
53+
}
54+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ru.mirea.practice.s0000001.n4;
2+
3+
import java.util.Calendar;
4+
import java.util.Date;
5+
import java.util.Scanner;
6+
7+
public final class DateTimeInput {
8+
private DateTimeInput() {}
9+
10+
public static void main(String[] args) {
11+
try (Scanner scn = new Scanner(System.in)) {
12+
System.out.print("Введите год: ");
13+
final int year = scn.nextInt();
14+
15+
System.out.print("Введите месяц (1-12): ");
16+
final int month = scn.nextInt() - 1;
17+
18+
System.out.print("Введите число: ");
19+
final int day = scn.nextInt();
20+
21+
System.out.print("Введите часы: ");
22+
final int hour = scn.nextInt();
23+
24+
System.out.print("Введите минуты: ");
25+
final int minute = scn.nextInt();
26+
27+
Calendar cal = Calendar.getInstance();
28+
cal.set(year, month, day, hour, minute);
29+
Date date = cal.getTime();
30+
31+
System.out.println("Созданная дата (Date): " + date);
32+
System.out.println("Созданная дата (Calendar): " + cal.getTime());
33+
}
34+
}
35+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package ru.mirea.practice.s0000001.n5;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
7+
public final class ListP {
8+
private ListP() {}
9+
10+
public static void main(String[] args) {
11+
List<Integer> arrayList = new ArrayList<>();
12+
List<Integer> linkedList = new LinkedList<>();
13+
14+
final int elementsCount = 100000;
15+
16+
for (int i = 0; i < elementsCount; i++) {
17+
arrayList.add(i);
18+
linkedList.add(i);
19+
}
20+
21+
System.out.println("Вставка в середину:");
22+
measureTime(() -> arrayList.add(elementsCount / 2, -1), "ArrayList");
23+
measureTime(() -> linkedList.add(elementsCount / 2, -1), "LinkedList");
24+
25+
System.out.println("Удаление из середины:");
26+
measureTime(() -> arrayList.remove(elementsCount / 2), "ArrayList");
27+
measureTime(() -> linkedList.remove(elementsCount / 2), "LinkedList");
28+
29+
System.out.println("Добавление в конец:");
30+
measureTime(() -> arrayList.add(-1), "ArrayList");
31+
measureTime(() -> linkedList.add(-1), "LinkedList");
32+
33+
System.out.println("Поиск элемента:");
34+
measureTime(() -> arrayList.contains(elementsCount - 1), "ArrayList");
35+
measureTime(() -> linkedList.contains(elementsCount - 1), "LinkedList");
36+
}
37+
38+
private static void measureTime(Runnable action, String listType) {
39+
long start = System.nanoTime();
40+
action.run();
41+
long end = System.nanoTime();
42+
System.out.println(listType + ": " + (end - start) + " нс");
43+
}
44+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p12</artifactId>
12+
<description>12 практическая</description>
13+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics;
5+
6+
public class Circle extends Shape {
7+
private int radius;
8+
9+
public Circle(Color color, int x, int y, int radius) {
10+
super(color, x, y);
11+
this.radius = radius;
12+
}
13+
14+
@Override
15+
public void draw(Graphics g) {
16+
g.setColor(color);
17+
g.fillOval(x, y, radius, radius);
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics;
5+
6+
public class Rectangle extends Shape {
7+
private int width;
8+
private int height;
9+
10+
public Rectangle(Color color, int x, int y, int width, int height) {
11+
super(color, x, y);
12+
this.width = width;
13+
this.height = height;
14+
}
15+
16+
@Override
17+
public void draw(Graphics g) {
18+
g.setColor(color);
19+
g.fillRect(x, y, width, height);
20+
}
21+
}

0 commit comments

Comments
 (0)