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

lab 20 #546

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/23K0114/23K0114-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: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>23K0114</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0114-p011</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.mirea.practice.s23k0114.lab1.task1;

import java.util.Date;

public abstract class AssignmentInfo {
public static void main(String[] args) {

String developerSurname = "Журавлева";

Date assignmentReceived = new Date(System.currentTimeMillis());

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

try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}

Date assignmentSubmitted = new Date();

System.out.println("Дата и время сдачи задания: " + assignmentSubmitted);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.mirea.practice.s23k0114.lab1.task2;

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

public abstract class UserDateCalendar {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {

System.out.print("Введите год: ");
final int year = scanner.nextInt();

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

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

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

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

Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, hour, minute);

Date date = calendar.getTime();

System.out.println("Объект Calendar: " + calendar.getTime());
System.out.println("Объект Date: " + date);
}
}
}

13 changes: 13 additions & 0 deletions students/23K0114/23K0114-p012/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: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>23K0114</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0114-p012</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.mirea.practice.s23k0114.lab1;

public final class Main {

private Main() {

}

public static void main(String[] args) {
System.out.println("вторая практическая работа!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.mirea.practice.s23k0114.lab1;

import java.util.Scanner;

/**
* Написать регулярное выражение, определяющее является ли данная
* строка строкой "abcdefghijklmnopqrstuv18340" или нет.
* a) пример правильных выражений: abcdefghijklmnopqrstuv18340
* b) пример неправильных выражений: abcdefghijklmnoasdfasdpqrstuv18340.
*/

public abstract class Task2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
String inp = sc.nextLine().strip();
if (inp.matches("abcdefghijklmnopqrstuv18340")) {
System.out.println("Введённая строка совпадает с: abcdefghijklmnopqrstuv18340");
} else {
System.out.println("Введённая строка не совпадает с: abcdefghijklmnopqrstuv18340");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.mirea.practice.s23k0114.lab1;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Дан текст со списками цен. Извлечь из него цены в USD, RUВ, EU.
* a) пример правильных выражений: 25.98 USD.
* b) пример неправильных выражений: 44 ERR, 0.004 EU.
*/

public abstract class Task3 {
public static void main(String[] args) {
System.out.println("Extracts first match only!");

final Pattern p = Pattern.compile("(\\d+\\.\\d\\d ((USD)|(RUB)|(EU)))");

try (Scanner sc = new Scanner(System.in)) {
String str = sc.nextLine();

Matcher m = p.matcher(str);
if (m.find()) {
System.out.println(m.group(1));
} else {
System.out.println("Nothing was matched.");
}
}
}
}
13 changes: 13 additions & 0 deletions students/23K0114/23K0114-p013/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: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>23K0114</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0114-p013</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.mirea.practice.s23k0114.lab1.task1;

import java.util.Locale;

public abstract class StringTask {

public static void main(String[] args) {
String str = "I like Java!!!";

char lastChar = str.charAt(str.length() - 1);
System.out.println("Последний символ: " + lastChar);

boolean endsWithExclamation = str.endsWith("!!!");
System.out.println("Заканчивается ли строка на '!!!': " + endsWithExclamation);

boolean startsWithILike = str.startsWith("I like");
System.out.println("Начинается ли строка с 'I like': " + startsWithILike);

boolean containsJava = str.contains("Java");
System.out.println("Содержит ли строка 'Java': " + containsJava);

int indexOfJava = str.indexOf("Java");
System.out.println("Позиция 'Java': " + indexOfJava);

String replacedStr = str.replace('a', 'o');
System.out.println("Строка с заменой 'a' на 'o': " + replacedStr);

String upperCaseStr = str.toUpperCase(Locale.ROOT);
System.out.println("Строка в верхнем регистре: " + upperCaseStr);

String lowerCaseStr = str.toLowerCase(Locale.ROOT);
System.out.println("Строка в нижнем регистре: " + lowerCaseStr);

String substringJava = str.substring(indexOfJava, indexOfJava + "Java".length());
System.out.println("Вырезанная строка 'Java': " + substringJava);
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s23k0114.lab1.task2;




public abstract class Main {
public static void main(String[] args) {
Person person1 = new Person("Пупкин", "Василий", "Иванович");
Person person2 = new Person("Матанов", "Петруха", null);
Person person3 = new Person("Шариков", null, null);

PersonFormatter formatter = new PersonFormatter();

System.out.println(formatter.getFullNameInitials(person1));
System.out.println(formatter.getFullNameInitials(person2));
System.out.println(formatter.getFullNameInitials(person3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.mirea.practice.s23k0114.lab1.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 getLastName() {
return lastName;
}

public String getFirstName() {
return firstName;
}

public String getMiddleName() {
return middleName;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ru.mirea.practice.s23k0114.lab1.task2;



public class PersonFormatter {

public String getFullNameInitials(Person person) {
StringBuilder result = new StringBuilder();

if (person.getLastName() != null && !person.getLastName().isEmpty()) {
result.append(person.getLastName());
}

if (person.getFirstName() != null && !person.getFirstName().isEmpty()) {
if (result.length() > 0) {
result.append(" ");
}
result.append(person.getFirstName().charAt(0)).append(".");
}

if (person.getMiddleName() != null && !person.getMiddleName().isEmpty()) {
result.append(person.getMiddleName().charAt(0)).append(".");
}

return result.toString();
}
}
13 changes: 13 additions & 0 deletions students/23K0114/23K0114-p014/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: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>23K0114</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0114-p014</artifactId>
<description>Массивы</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ru.mirea.practice.s23k0114.lab1.task1;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class StringManipulator {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

try {
System.out.print("Введите строку для обработки: ");
String inputString = scanner.nextLine();

System.out.print("Введите регулярное выражение для разбивки строки: ");
String regex = scanner.nextLine();

Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(inputString);

System.out.println("Результаты разбиения:");
while (matcher.find()) {
System.out.println(matcher.group());
}

} finally {
if (scanner != null) {
scanner.close();
}
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.mirea.practice.s23k0114.lab1.task2;

import java.util.Scanner;
import java.util.regex.Pattern;

public abstract class StringValidator {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

try {
System.out.print("Введите строку для проверки: ");
String inputString = scanner.nextLine();

String regex = "^abcdefghijklmnopqrstuv18340$";

boolean isValid = Pattern.matches(regex, inputString);

if (isValid) {
System.out.println("Строка корректна.");
} else {
System.out.println("Строка некорректна.");
}

} finally {
if (scanner != null) {
scanner.close();
}
}
}
}
13 changes: 13 additions & 0 deletions students/23K0114/23K0114-p015/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: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>23K0114</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0114-p015</artifactId>
<description>Массивы</description>
</project>
Loading
Loading