Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

лабораторная№16 18 #517

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p--/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p12</artifactId>
<description>12 практическая</description>
</project>
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p11/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p11</artifactId>
<description>11 практическая</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s0000001.n1;

import java.util.Date;

public final class Fam {
private Fam() {}

public static void main(String[] args) {
String fam = "Самохин";
Date datPoluch = new Date();

System.out.println("Разработчик: " + fam);
System.out.println("Дата и время получения задания: " + datPoluch);

Date datSdacha = new Date();
System.out.println("Дата и время сдачи задания: " + datSdacha);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.mirea.practice.s0000001.n2;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;

public final class DateCompare {
private DateCompare() {}

public static void main(String[] args) {
try (Scanner scn = new Scanner(System.in)) {
System.out.print("Введите дату в формате ГГГГ-ММ-ДД: ");
String userDateStr = scn.nextLine();

SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try {
Date userDate = fmt.parse(userDateStr);
Date currDate = new Date();

if (userDate.equals(currDate)) {
System.out.println("Даты совпадают");
} else if (userDate.before(currDate)) {
System.out.println("Введённая дата раньше текущей");
} else {
System.out.println("Введённая дата позже текущей");
}
} catch (ParseException e) {
System.out.println("Неверный формат даты");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.mirea.practice.s0000001.n3;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Student {
private String firstName;
private String lastName;
private String specialty;
private int course;
private String group;
private Date birthDate;

public Student(String firstName, String lastName, String specialty, int course, String group, Date birthDate) {
this.firstName = firstName;
this.lastName = lastName;
this.specialty = specialty;
this.course = course;
this.group = group;
this.birthDate = birthDate;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

@Override
public String toString() {
SimpleDateFormat shortFmt = new SimpleDateFormat("dd.MM.yy");
SimpleDateFormat mediumFmt = new SimpleDateFormat("dd MMM yyyy");
SimpleDateFormat longFmt = new SimpleDateFormat("EEEE, dd MMMM yyyy");

return "Имя: " + firstName + " " + lastName + "\n"
+ "Специальность: " + specialty + "\n"
+ "Курс: " + course + "\n"
+ "Группа: " + group + "\n"
+ "Дата рождения (короткий формат): "
+ shortFmt.format(birthDate) + "\n"
+ "Дата рождения (средний формат): "
+ mediumFmt.format(birthDate) + "\n"
+ "Дата рождения (полный формат): "
+ longFmt.format(birthDate);
}

public static void main(String[] args) {
Date birth = new Date(05, 6, 11);
Student stud = new Student("Михаил", "Самохин", "Авт", 2, "КАБО-02-23", birth);
System.out.println(stud);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.mirea.practice.s0000001.n4;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public final class DateTimeInput {
private DateTimeInput() {}

public static void main(String[] args) {
try (Scanner scn = new Scanner(System.in)) {
System.out.print("Введите год: ");
final int year = scn.nextInt();

System.out.print("Введите месяц (1-12): ");
final int month = scn.nextInt() - 1;

System.out.print("Введите число: ");
final int day = scn.nextInt();

System.out.print("Введите часы: ");
final int hour = scn.nextInt();

System.out.print("Введите минуты: ");
final int minute = scn.nextInt();

Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, minute);
Date date = cal.getTime();

System.out.println("Созданная дата (Date): " + date);
System.out.println("Созданная дата (Calendar): " + cal.getTime());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.mirea.practice.s0000001.n5;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public final class ListP {
private ListP() {}

public static void main(String[] args) {
List<Integer> arrayList = new ArrayList<>();
List<Integer> linkedList = new LinkedList<>();

final int elementsCount = 100000;

for (int i = 0; i < elementsCount; i++) {
arrayList.add(i);
linkedList.add(i);
}

System.out.println("Вставка в середину:");
measureTime(() -> arrayList.add(elementsCount / 2, -1), "ArrayList");
measureTime(() -> linkedList.add(elementsCount / 2, -1), "LinkedList");

System.out.println("Удаление из середины:");
measureTime(() -> arrayList.remove(elementsCount / 2), "ArrayList");
measureTime(() -> linkedList.remove(elementsCount / 2), "LinkedList");

System.out.println("Добавление в конец:");
measureTime(() -> arrayList.add(-1), "ArrayList");
measureTime(() -> linkedList.add(-1), "LinkedList");

System.out.println("Поиск элемента:");
measureTime(() -> arrayList.contains(elementsCount - 1), "ArrayList");
measureTime(() -> linkedList.contains(elementsCount - 1), "LinkedList");
}

private static void measureTime(Runnable action, String listType) {
long start = System.nanoTime();
action.run();
long end = System.nanoTime();
System.out.println(listType + ": " + (end - start) + " нс");
}
}
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p12/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p12</artifactId>
<description>12 практическая</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.mirea.practice.s0000001.n1;

import java.awt.Color;
import java.awt.Graphics;

public class Circle extends Shape {
private int radius;

public Circle(Color color, int x, int y, int radius) {
super(color, x, y);
this.radius = radius;
}

@Override
public void draw(Graphics g) {
g.setColor(color);
g.fillOval(x, y, radius, radius);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.mirea.practice.s0000001.n1;

import java.awt.Color;
import java.awt.Graphics;

public class Rectangle extends Shape {
private int width;
private int height;

public Rectangle(Color color, int x, int y, int width, int height) {
super(color, x, y);
this.width = width;
this.height = height;
}

@Override
public void draw(Graphics g) {
g.setColor(color);
g.fillRect(x, y, width, height);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s0000001.n1;

import java.awt.Color;
import java.awt.Graphics;

public abstract class Shape {
protected Color color;
protected int x;
protected int y;

public Shape(Color color, int x, int y) {
this.color = color;
this.x = x;
this.y = y;
}

public abstract void draw(Graphics g);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.mirea.practice.s0000001.n1;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.Random;
import java.util.List;
import java.awt.Graphics;
import java.awt.Color;

public class ShapeWindow extends JPanel {
private List<Shape> shapes = new ArrayList<>();

public ShapeWindow() {
Random rand = new Random();
for (int i = 0; i < 20; i++) {
Color color = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
int x = rand.nextInt(400);
int y = rand.nextInt(400);

if (rand.nextBoolean()) {
shapes.add(new Circle(color, x, y, rand.nextInt(50) + 10));
} else {
shapes.add(new Rectangle(color, x, y, rand.nextInt(50) + 10, rand.nextInt(50) + 10));
}
}
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for (Shape shape : shapes) {
shape.draw(g);
}
}

public static void main(String[] args) {
JFrame frame = new JFrame("Random Shapes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.add(new ShapeWindow());
frame.setVisible(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ru.mirea.practice.s0000001.n2;

import javax.swing.JFrame;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.io.IOException;

public class ImageWindow extends JFrame {
private Image img;

public ImageWindow(String path) {
try {
img = ImageIO.read(new File(path));
} catch (IOException e) {
System.out.println("Ошибка загрузки изображения:( " + e.getMessage());
System.exit(1);
}

setTitle("Image_cool_Viewer");
setSize(500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

@Override
public void paint(Graphics g) {
super.paint(g);
if (img != null) {
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}

public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Пожалуйста, укажите путь к изображению в аргументах командной строки ^_^");
System.exit(1);
}
String imagePath = args[0];
ImageWindow window = new ImageWindow(imagePath);
window.setVisible(true);
}
}
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p13/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p13</artifactId>
<description>13 практическая</description>
</project>
Loading
Loading