Skip to content

Commit

Permalink
Практическая работа 1-20
Browse files Browse the repository at this point in the history
  • Loading branch information
banbanovich committed Nov 7, 2024
1 parent b794d8b commit 4b8dd84
Show file tree
Hide file tree
Showing 49 changed files with 1,428 additions and 0 deletions.
13 changes: 13 additions & 0 deletions students/23K0690/23K0690-p011/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>23K0690</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0690-p011</artifactId>
<description>11 задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mirea.practice.s23k0690;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public final class Task2 {
private Task2() {

}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
LocalDateTime currentDateTime = LocalDateTime.now();
System.out.println("Текущая дата и время: " + currentDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
System.out.print("Введите дату и время (ГГГГ-ММ-ДД ЧЧ:ММ:СС (Пример:2024-10-29 12:43:29)): ");
String userInput = scanner.nextLine();
LocalDateTime userDateTime = LocalDateTime.parse(userInput, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
if (userDateTime.isBefore(currentDateTime)) {
System.out.println("Введенная дата и время раньше текущего времени.");
} else if (userDateTime.isAfter(currentDateTime)) {
System.out.println("Введенная дата и время позже текущего времени.");
} else {
System.out.println("Введенная дата и время совпадает с текущим временем.");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.mirea.practice.s23k0690;

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

public final class Task4 {
private Task4() {

}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Введите год (например, 2023): ");
final int year = scanner.nextInt();
System.out.print("Введите месяц (1-12): ");
final int month = scanner.nextInt();
System.out.print("Введите число (1-31): ");
final int day = scanner.nextInt();
System.out.print("Введите часы (0-23): ");
final int hours = scanner.nextInt();
System.out.print("Введите минуты (0-59): ");
final int minutes = scanner.nextInt();
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, day, hours, minutes, 0);
calendar.set(Calendar.MILLISECOND, 0);
SimpleDateFormat calendarFormat = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("Созданный объект Calendar: " + calendarFormat.format(calendar.getTime()));
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
Date date = calendar.getTime();
System.out.println("Созданный объект Date: " + dateFormat.format(date));
}
}
}
13 changes: 13 additions & 0 deletions students/23K0690/23K0690-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>23K0690</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0690-p12</artifactId>
<description>12 Задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.mirea.practice.s23k0690;

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

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.s23k0690;

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

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.s23k0690;

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

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

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,49 @@
package ru.mirea.practice.s23k0690;

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


public class Task1 extends JPanel {
private Shape[] shapes;

public Task1() {
shapes = new Shape[20];
Random random = new Random();

for (int i = 0; i < shapes.length; i++) {
Color randomColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
int x = random.nextInt(800);
int y = random.nextInt(600);
if (random.nextBoolean()) {
int radius = random.nextInt(100) + 20; // Радиус от 20 до 119
shapes[i] = new Circle(randomColor, x, y, radius);
} else {
int width = random.nextInt(100) + 20; // Ширина от 20 до 119
int height = random.nextInt(100) + 20; // Высота от 20 до 119
shapes[i] = new Rectangle(randomColor, x, y, width, height);
}
}
}

@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("Случайные фигуры");
Task1 randomShapes = new Task1();
frame.add(randomShapes);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.mirea.practice.s23k0690;

import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Dimension;

public final class Task2 {
private Task2() {}

public static void main(String[] args) {
displayImage();
}

private static void displayImage() {
try (Scanner in = new Scanner(System.in)) {
System.out.print("Введите полный путь к изображению: ");
String imagePath = in.nextLine();
JFrame frame = new JFrame("Показываем картинку");
ImageIcon icon = new ImageIcon(imagePath);
if (icon.getIconWidth() == -1) {
System.out.println("Ошибка: изображение не найдено по пути: " + imagePath);
return;
}
JPanel panel = new JPanel();
panel.add(new JLabel(icon));
frame.add(panel);
frame.setSize(new Dimension(700, 500));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
}
13 changes: 13 additions & 0 deletions students/23K0690/23K0690-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>23K0690</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0690-p13</artifactId>
<description>13 Задание</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ru.mirea.practice.s23k0690;

public final class Person {
private String lastName;
private String firstName;
private String middleName;

private Person() {}

public Person(String lastName, String firstName, String middleName) {
this.lastName = lastName;
this.firstName = firstName;
this.middleName = middleName;
}

public String getFullName() {
StringBuilder fullName = new StringBuilder(lastName);

if (firstName != null && !firstName.isEmpty()) {
fullName.append(" ").append(firstName.charAt(0)).append(".");
}

if (middleName != null && !middleName.isEmpty()) {
fullName.append(" ").append(middleName.charAt(0)).append(".");
}

return fullName.toString();
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getMiddleName() {
return middleName;
}

public void setMiddleName(String middleName) {
this.middleName = middleName;
}

public static void main(String[] args) {
Person person1 = new Person("Иванов", "Иван", "Иванович");
Person person2 = new Person("Петров", "Петр", null);
Person person3 = new Person("Сидоров", null, null);

System.out.println(person1.getFullName());
System.out.println(person2.getFullName());
System.out.println(person3.getFullName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ru.mirea.practice.s23k0690;

import java.util.Scanner;

public final class Task4 {
private String phoneNumber;

private Task4() {}

public Task4(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String format() {
String formattedNumber;
String digits = phoneNumber.replaceAll("\\D", "");
if (digits.startsWith("8")) {
digits = "7" + digits.substring(1);
}

if (digits.startsWith("+")) {
formattedNumber = formatInternational(digits);
} else {
formattedNumber = formatDomestic(digits);
}
return formattedNumber;
}

private String formatInternational(String number) {
String countryCode = number.substring(1, number.length() - 10);
String localNumber = number.substring(number.length() - 10);
return "+" + countryCode + " " + localNumber.substring(0, 3) + "–" + localNumber.substring(3, 6) + "–" + localNumber.substring(6);
}

private String formatDomestic(String number) {
String localNumber = number.substring(1);
return "+7 " + localNumber.substring(0, 3) + "–" + localNumber.substring(3, 6) + "–" + localNumber.substring(6);
}

public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Введите телефонный номер в формате +<Код страны> <Номер 10 цифр> или 8<Номер 10 цифр>: ");
String userInput = scanner.nextLine();
Task4 formatter = new Task4(userInput);
String formattedNumber = formatter.format();
System.out.println("Отформатированный номер: " + formattedNumber);
}
}
}
13 changes: 13 additions & 0 deletions students/23K0690/23K0690-p14/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>23K0690</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0690-p14</artifactId>
<description>14 задание</description>
</project>
Loading

0 comments on commit 4b8dd84

Please sign in to comment.