-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b794d8b
commit 4b8dd84
Showing
49 changed files
with
1,428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
students/23K0690/23K0690-p011/src/main/java/ru/mirea/practice/s23k0690/Task2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Введенная дата и время совпадает с текущим временем."); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
students/23K0690/23K0690-p011/src/main/java/ru/mirea/practice/s23k0690/Task4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
19 changes: 19 additions & 0 deletions
19
students/23K0690/23K0690-p12/src/main/java/ru/mirea/practice/s23k0690/Circle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
students/23K0690/23K0690-p12/src/main/java/ru/mirea/practice/s23k0690/Rectangle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
students/23K0690/23K0690-p12/src/main/java/ru/mirea/practice/s23k0690/Shape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
49 changes: 49 additions & 0 deletions
49
students/23K0690/23K0690-p12/src/main/java/ru/mirea/practice/s23k0690/Task1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
students/23K0690/23K0690-p12/src/main/java/ru/mirea/practice/s23k0690/Task2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
63 changes: 63 additions & 0 deletions
63
students/23K0690/23K0690-p13/src/main/java/ru/mirea/practice/s23k0690/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
students/23K0690/23K0690-p13/src/main/java/ru/mirea/practice/s23k0690/Task4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.