-
Notifications
You must be signed in to change notification settings - Fork 70
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 #453 from Timmmmofey/features/lab15
Features/lab15
- Loading branch information
Showing
8 changed files
with
255 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>23K1302</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23K1302-p13</artifactId> | ||
<description>Задание 13</description> | ||
</project> |
37 changes: 37 additions & 0 deletions
37
students/23K1302/23K1302-p13/src/main/java/ru/mirea/practice/s0000001/Ex1.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,37 @@ | ||
package ru.mirea.practice.s0000001; | ||
|
||
import java.util.Locale; | ||
|
||
public final class Ex1 { | ||
|
||
private Ex1() { | ||
// 123 | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
String str = "I like Java!!!"; | ||
|
||
System.out.println("1. Исходная строка: " + str); | ||
|
||
System.out.println("2. Последний символ: " + str.charAt(str.length() - 1)); | ||
|
||
System.out.println("3. Заканчивается на '!!!': " + str.endsWith("!!!")); | ||
|
||
System.out.println("4. Начинается с 'I like': " + str.startsWith("I like")); | ||
|
||
System.out.println("5. Содержит 'Java': " + str.contains("Java")); | ||
|
||
System.out.println("6. Позиция 'Java': " + str.indexOf("Java")); | ||
|
||
String replacedStr = str.replace('a', 'o'); | ||
System.out.println("7. Замена 'a' на 'o': " + replacedStr); | ||
|
||
System.out.println("8. В верхнем регистре: " + str.toUpperCase(Locale.ROOT)); | ||
|
||
System.out.println("9. В нижнем регистре: " + str.toLowerCase(Locale.ROOT)); | ||
|
||
String substringStr = str.substring(0, str.indexOf("Java")) + str.substring(str.indexOf("Java") + 4, str.length() - 1); | ||
System.out.println("10. Вырезанная подстрока 'Java': " + substringStr); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
students/23K1302/23K1302-p13/src/main/java/ru/mirea/practice/s0000001/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,33 @@ | ||
package ru.mirea.practice.s0000001; | ||
|
||
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); | ||
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 static void main(String[] args) { | ||
Person person1 = new Person("Мясников", "Тимофей", "Михайлович"); | ||
Person person2 = new Person("Михаил", "Мясников", null); | ||
|
||
System.out.println("Полное имя первого человека: " + person1.getFullName()); | ||
System.out.println("Полное имя второго человека: " + person2.getFullName()); | ||
} | ||
} |
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>23K1302</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23K1302-p14</artifactId> | ||
<description>Задание 14</description> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
students/23K1302/23K1302-p14/src/main/java/ru/mirea/practice/s0000001/Main.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,39 @@ | ||
package ru.mirea.practice.s0000001; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public final class Main { | ||
|
||
private Main() { | ||
// 123 | ||
} | ||
|
||
public static void splitString(String input, String regex) { | ||
Pattern pattern = Pattern.compile(regex); | ||
String[] parts = pattern.split(input); | ||
System.out.println("Строка до разбивки: " + input); | ||
System.out.println("Результат разбивки строки:"); | ||
for (String part : parts) { | ||
System.out.println(part); | ||
} | ||
} | ||
|
||
public static boolean isValidString(String input) { | ||
String regex = "^abcdefghijklmnopqrstuv18340$"; | ||
return Pattern.matches(regex, input); | ||
} | ||
|
||
public static void main(String[] args) { | ||
String inputString = "Hello,123World,456Example"; | ||
String regex = "\\d+"; // \\d+ значит, что строка будет разбита стоящими в ней числами | ||
splitString(inputString, regex); | ||
|
||
String testString1 = "abcdefghijklmnopqrstuv18340"; | ||
String testString2 = "abcdefghijklmnoasdfasdpqrstuv18340"; | ||
|
||
System.out.println("Проверка строки: " + testString1 + " - " | ||
+ (isValidString(testString1) ? "Соответствует" : "Не соответствует")); | ||
System.out.println("Проверка строки: " + testString2 + " - " | ||
+ (isValidString(testString2) ? "Соответствует" : "Не соответствует")); | ||
} | ||
} |
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>23K1302</artifactId> | ||
<groupId>ru.mirea.practice</groupId> | ||
<version>2024.1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>23K1302-p15</artifactId> | ||
<description>Задание 15</description> | ||
</project> |
104 changes: 104 additions & 0 deletions
104
students/23K1302/23K1302-p15/src/main/java/ru/mirea/practice/s0000001/Main.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,104 @@ | ||
package ru.mirea.practice.s0000001; | ||
|
||
import java.awt.Button; | ||
import java.awt.Frame; | ||
import java.awt.TextField; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
|
||
public final class Main { | ||
|
||
private Main() { | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
final Frame f = new Frame("Calculator Example"); | ||
final TextField tf1 = new TextField(); | ||
tf1.setBounds(50, 50, 150, 20); | ||
|
||
final TextField tf2 = new TextField(); | ||
tf2.setBounds(50, 80, 150, 20); | ||
|
||
final TextField tfResult = new TextField(); | ||
tfResult.setBounds(50, 140, 150, 20); | ||
tfResult.setEditable(false); | ||
|
||
Button addButton = new Button("+"); | ||
addButton.setBounds(50, 110, 50, 30); | ||
|
||
Button subtractButton = new Button("-"); | ||
subtractButton.setBounds(110, 110, 50, 30); | ||
|
||
Button multiplyButton = new Button("*"); | ||
multiplyButton.setBounds(170, 110, 50, 30); | ||
|
||
Button divideButton = new Button("/"); | ||
divideButton.setBounds(230, 110, 50, 30); | ||
|
||
addButton.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
double num1 = Double.parseDouble(tf1.getText()); | ||
double num2 = Double.parseDouble(tf2.getText()); | ||
tfResult.setText(String.valueOf(num1 + num2)); | ||
} catch (NumberFormatException ex) { | ||
tfResult.setText("Ошибка ввода"); | ||
} | ||
} | ||
}); | ||
|
||
subtractButton.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
double num1 = Double.parseDouble(tf1.getText()); | ||
double num2 = Double.parseDouble(tf2.getText()); | ||
tfResult.setText(String.valueOf(num1 - num2)); | ||
} catch (NumberFormatException ex) { | ||
tfResult.setText("Ошибка ввода"); | ||
} | ||
} | ||
}); | ||
|
||
multiplyButton.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
double num1 = Double.parseDouble(tf1.getText()); | ||
double num2 = Double.parseDouble(tf2.getText()); | ||
tfResult.setText(String.valueOf(num1 * num2)); | ||
} catch (NumberFormatException ex) { | ||
tfResult.setText("Ошибка ввода"); | ||
} | ||
} | ||
}); | ||
|
||
divideButton.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
double num1 = Double.parseDouble(tf1.getText()); | ||
double num2 = Double.parseDouble(tf2.getText()); | ||
if (num2 != 0) { | ||
tfResult.setText(String.valueOf(num1 / num2)); | ||
} else { | ||
tfResult.setText("На ноль делить нельзя"); | ||
} | ||
} catch (NumberFormatException ex) { | ||
tfResult.setText("Ошибка ввода"); | ||
} | ||
} | ||
}); | ||
|
||
f.add(tf1); | ||
f.add(tf2); | ||
f.add(tfResult); | ||
f.add(addButton); | ||
f.add(subtractButton); | ||
f.add(multiplyButton); | ||
f.add(divideButton); | ||
|
||
f.setSize(400, 300); | ||
f.setLayout(null); | ||
f.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