-
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.
Merge pull request #490 from murtazinail/main
Лабораторная №11-№16
- Loading branch information
Showing
59 changed files
with
1,532 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
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>23F0011</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23F0011-p11</artifactId> | ||
<description>Массивы</description> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
students/23F0011/23F0011-p11/src/main/java/ru/mirea/practice/s23f0011/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,21 @@ | ||
package ru.mirea.practice.s23f0011; | ||
|
||
import java.util.Date; | ||
|
||
public abstract class Task1 { | ||
public static void main(String[] args) { | ||
// Фамилия разработчика | ||
String developerSurname = "Муртазин"; | ||
|
||
// Дата и время получения задания (указываем вручную) | ||
String assignmentReceived = "2024-11-01 10:00"; | ||
|
||
// Текущая дата и время сдачи задания | ||
Date submissionDate = new Date(); | ||
|
||
// Вывод информации | ||
System.out.println("Фамилия разработчика: " + developerSurname); | ||
System.out.println("Дата и время получения задания: " + assignmentReceived); | ||
System.out.println("Дата и время сдачи задания: " + submissionDate); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
students/23F0011/23F0011-p11/src/main/java/ru/mirea/practice/s23f0011/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,46 @@ | ||
package ru.mirea.practice.s23f0011; | ||
|
||
import java.util.Calendar; | ||
import java.util.GregorianCalendar; | ||
import java.util.Scanner; | ||
|
||
public abstract class Task2 { | ||
public static void main(String[] args) { | ||
// Создаем объект Scanner для ввода данных от пользователя | ||
try (Scanner scanner = new Scanner(System.in)) { | ||
|
||
// Получаем текущую дату | ||
Calendar currentDate = GregorianCalendar.getInstance(); | ||
System.out.println("Текущая дата: " + currentDate.getTime()); | ||
|
||
// Запрашиваем у пользователя ввод даты | ||
System.out.print("Введите дату (формат: ГГГГ-ММ-ДД ЧЧ:ММ:СС): "); | ||
String userInput = scanner.nextLine(); | ||
|
||
// Разделяем введенную строку на составляющие | ||
String[] dateTimeParts = userInput.split(" "); | ||
String[] dateParts = dateTimeParts[0].split("-"); | ||
String[] timeParts = dateTimeParts[1].split(":"); | ||
|
||
// Создаем объект Calendar для введенной даты | ||
Calendar userDate = new GregorianCalendar( | ||
Integer.parseInt(dateParts[0]), // Год | ||
Integer.parseInt(dateParts[1]) - 1, // Месяцы начинаются с 0 | ||
Integer.parseInt(dateParts[2]), | ||
Integer.parseInt(timeParts[0]), | ||
Integer.parseInt(timeParts[1]), | ||
Integer.parseInt(timeParts[2]) | ||
); | ||
|
||
// Сравниваем даты | ||
if (userDate.before(currentDate)) { | ||
System.out.println("Введенная дата раньше текущей даты."); | ||
} else if (userDate.after(currentDate)) { | ||
System.out.println("Введенная дата позже текущей даты."); | ||
} else { | ||
System.out.println("Введенная дата совпадает с текущей датой."); | ||
} | ||
} | ||
|
||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
students/23F0011/23F0011-p11/src/main/java/ru/mirea/practice/s23f0011/task3/Student2.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,40 @@ | ||
package ru.mirea.practice.s23f0011.task3; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class Student2 { | ||
private final String name; | ||
private final Date birthDate; | ||
|
||
// Конструктор | ||
public Student2(String name, Date birthDate) { | ||
this.name = name; | ||
this.birthDate = birthDate; | ||
} | ||
|
||
// Геттер для имени | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
// Геттер для даты рождения | ||
public Date getBirthDate() { | ||
return birthDate; | ||
} | ||
|
||
// Метод для получения строкового представления даты рождения в заданном формате | ||
public String getFormattedBirthDate(String format) { | ||
SimpleDateFormat dateFormat = new SimpleDateFormat(format); | ||
return dateFormat.format(birthDate); | ||
} | ||
|
||
// Переопределенный метод toString() | ||
@Override | ||
public String toString() { | ||
return "Student{" | ||
+ "name='" + name + '\'' | ||
+ ", birthDate=" + getFormattedBirthDate("yyyy-MM-dd") // Стандартный формат | ||
+ '}'; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
students/23F0011/23F0011-p11/src/main/java/ru/mirea/practice/s23f0011/task3/Tester.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.s23f0011.task3; | ||
|
||
import java.util.Date; | ||
|
||
public abstract class Tester { | ||
public static void main(String[] args) { | ||
// Пример использования класса Student | ||
Student2 student = new Student2("Иван Иванов", new Date()); | ||
|
||
// Вывод информации о студенте | ||
System.out.println(student); | ||
|
||
// Вывод даты рождения в различных форматах | ||
System.out.println("Дата рождения (короткий формат): " + student.getFormattedBirthDate("dd.MM.yy")); | ||
System.out.println("Дата рождения (средний формат): " + student.getFormattedBirthDate("dd MMMM yyyy")); | ||
System.out.println("Дата рождения (полный формат): " + student.getFormattedBirthDate("EEEE, dd MMMM yyyy")); | ||
} | ||
} |
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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
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>23F0011</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23F0011-p12</artifactId> | ||
<description>Массивы</description> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
students/23F0011/23F0011-p12/src/main/java/ru/mirea/practice/s23f0011/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.s23f0011; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
class Circle extends Shape { | ||
private final 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 - radius, y - radius, radius * 2, radius * 2); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
students/23F0011/23F0011-p12/src/main/java/ru/mirea/practice/s23f0011/RandomShapes.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,52 @@ | ||
package ru.mirea.practice.s23f0011; | ||
|
||
import javax.swing.JPanel; | ||
import javax.swing.JFrame; | ||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
import java.util.Random; | ||
|
||
public class RandomShapes extends JPanel { | ||
private final Shape[] shapes; | ||
|
||
public RandomShapes() { | ||
shapes = new Shape[20]; | ||
Random random = new Random(); | ||
|
||
for (int i = 0; i < shapes.length; i++) { | ||
// Генерируем случайный цвет | ||
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)); | ||
// Генерируем случайные позиции | ||
int x = random.nextInt(400); | ||
int y = random.nextInt(400); | ||
// Генерируем случайный тип фигуры | ||
if (random.nextBoolean()) { | ||
// Создаем круг с радиусом от 10 до 50 | ||
int radius = 10 + random.nextInt(41); | ||
shapes[i] = new Circle(color, x, y, radius); | ||
} else { | ||
// Создаем прямоугольник с шириной и высотой от 20 до 80 | ||
int width = 20 + random.nextInt(61); | ||
int height = 20 + random.nextInt(61); | ||
shapes[i] = new RectangleShape(color, x, y, width, height); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
JFrame frame = new JFrame("Случайные фигуры"); | ||
RandomShapes panel = new RandomShapes(); | ||
frame.add(panel); | ||
frame.setSize(500, 500); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setVisible(true); | ||
} | ||
|
||
@Override | ||
protected void paintComponent(Graphics g) { | ||
super.paintComponent(g); | ||
for (Shape shape : shapes) { | ||
shape.draw(g); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
students/23F0011/23F0011-p12/src/main/java/ru/mirea/practice/s23f0011/RectangleShape.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.s23f0011; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
class RectangleShape extends Shape { | ||
private final int width; | ||
private final int height; | ||
|
||
public RectangleShape(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/23F0011/23F0011-p12/src/main/java/ru/mirea/practice/s23f0011/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.s23f0011; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
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); | ||
} |
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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
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>23F0011</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23F0011-p13</artifactId> | ||
<description>Массивы</description> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
...3F0011/23F0011-p13/src/main/java/ru/mirea/practice/s23f0011/task1/Stringmanipulation.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,45 @@ | ||
package ru.mirea.practice.s23f0011.task1; | ||
|
||
import java.util.Locale; | ||
|
||
public abstract class Stringmanipulation { | ||
public static void processString(String input) { | ||
// 1. Распечатать последний символ строки | ||
char lastChar = input.charAt(input.length() - 1); | ||
System.out.println("Последний символ: " + lastChar); | ||
|
||
// 2. Проверить, заканчивается ли строка подстрокой "!!!" | ||
boolean endsWithExclamation = input.endsWith("!!!"); | ||
System.out.println("Заканчивается на '!!!': " + endsWithExclamation); | ||
|
||
// 3. Проверить, начинается ли строка подстрокой "I like" | ||
boolean startsWithILike = input.startsWith("I like"); | ||
System.out.println("Начинается на 'I like': " + startsWithILike); | ||
|
||
// 4. Проверить, содержит ли строка подстроку "Java" | ||
boolean containsJava = input.contains("Java"); | ||
System.out.println("Содержит 'Java': " + containsJava); | ||
|
||
// 5. Найти позицию подстроки "Java" | ||
int javaPosition = input.indexOf("Java"); | ||
System.out.println("Позиция 'Java': " + javaPosition); | ||
|
||
// 6. Заменить все символы "а" на "о" | ||
String replacedString = input.replace('a', 'o'); | ||
System.out.println("Строка после замены 'а' на 'о': " + replacedString); | ||
|
||
// 7. Преобразовать строку к верхнему регистру | ||
String upperCaseString = input.toUpperCase(Locale.ENGLISH); | ||
System.out.println("Строка в верхнем регистре: " + upperCaseString); | ||
|
||
// 8. Преобразовать строку к нижнему регистру | ||
String lowerCaseString = input.toLowerCase(Locale.ENGLISH); | ||
System.out.println("Строка в нижнем регистре: " + lowerCaseString); | ||
|
||
// 9. Вырезать подстроку "Java" из строки | ||
int start = javaPosition; // Начальная позиция подстроки "Java" | ||
int end = start + "Java".length(); // Конечная позиция | ||
String substringJava = input.substring(start, end); | ||
System.out.println("Вырезанная подстрока: " + substringJava); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
students/23F0011/23F0011-p13/src/main/java/ru/mirea/practice/s23f0011/task1/Tester.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,10 @@ | ||
package ru.mirea.practice.s23f0011.task1; | ||
|
||
import static ru.mirea.practice.s23f0011.task1.Stringmanipulation.processString; | ||
|
||
public abstract class Tester { | ||
public static void main(String[] args) { | ||
String input = "I like Java!!!"; // Исходная строка | ||
processString(input); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
students/23F0011/23F0011-p13/src/main/java/ru/mirea/practice/s23f0011/task2/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,31 @@ | ||
package ru.mirea.practice.s23f0011.task2; | ||
|
||
public class Person { | ||
private String lastName; // Фамилия | ||
private String firstName; // Имя | ||
private String middleName; // Отчество | ||
|
||
// Конструктор | ||
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); // Используем StringBuilder для оптимизации | ||
|
||
// Добавляем инициал имени, если оно не пустое | ||
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(); // Возвращаем строку | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
students/23F0011/23F0011-p13/src/main/java/ru/mirea/practice/s23f0011/task2/Tester.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.s23f0011.task2; | ||
|
||
public abstract class Tester { | ||
public static void main(String[] args) { | ||
// Примеры использования класса Person | ||
Person person1 = new Person("Иванов", "Иван", "Иванович"); | ||
Person person2 = new Person("Петров", "Петр", null); | ||
Person person3 = new Person("Сидоров", null, "Сидорович"); | ||
Person person4 = new Person("Кузнецов", "", "Алексеевич"); | ||
Person person5 = new Person("Смирнов", null, null); | ||
|
||
// Выводим полные имена | ||
System.out.println(person1.getFullName()); // Иванов И.И. | ||
System.out.println(person2.getFullName()); // Петров П. | ||
System.out.println(person3.getFullName()); // Сидоров С. | ||
System.out.println(person4.getFullName()); // Кузнецов А. | ||
System.out.println(person5.getFullName()); // Смирнов | ||
} | ||
} |
Oops, something went wrong.