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

Practics 11,13,14,17-20 #468

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/23K0563/23K0563-p11/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>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p11</artifactId>
<description>11</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mirea.lab11;

/* Написать программу, выводящую фамилию разработчика, дату и время
получения задания, а также дату и время сдачи задания. Для получения
последней даты и времени использовать класс Date из пакета java.util.*
(Объявление Dated=newDate() или метод System.currentTimeMillis(). */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public abstract class Prac11p1 {
public static void main(String[] args) {
SimpleDateFormat f = new SimpleDateFormat("EEEE, dd.MM.yyyy в HH:mm:ss");
Calendar rec = new GregorianCalendar(2024, Calendar.SEPTEMBER, 4, 9, 0, 0);
Calendar out = Calendar.getInstance();
System.out.println("Разработчик: Сидоров");
System.out.println("Дата получения работы: " + f.format(rec.getTime()));
System.out.println("Дата сдачи работы: " + f.format(out.getTime()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mirea.lab11;

/* Приложение, сравнивающее текущую дату и дату, введенную
пользователем c текущим системным временем */

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

public abstract class Prac11p2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy");
System.out.print("\nВведите дату(dd.mm.yyyy): ");
String inp = sc.nextLine();
Calendar user = Calendar.getInstance();
if (inp.length() == 10) {
user.set(Calendar.DAY_OF_MONTH, Integer.parseInt(inp.substring(0, 2)));
user.set(Calendar.MONTH, Integer.parseInt(inp.substring(3, 5)) - 1);
user.set(Calendar.YEAR, Integer.parseInt(inp.substring(6)));
Calendar now = Calendar.getInstance();
long u = user.getTimeInMillis();
long n = now.getTimeInMillis();
System.out.println("Разница между " + f.format(user.getTime()) + " и " + f.format(now.getTime())
+ " составляет " + (int) ((double) Math.abs(u - n) / 1000 / 60 / 60 / 24) + " дня.");
} else {
System.out.println("Неверный ввод даты");
System.exit(0);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mirea.lab11;

/* Напишите пользовательский код, который формирует объекты Date и
Calendar по следующим данным, вводимым пользователем:
<Год><Месяц><Число>
<Часы1><минуты> */

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

public abstract class Prac11p4 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Введите формат вывода даты\nИспользуйте <Год><Месяц><Число><Часы1><минуты>:");
String inp = sc.nextLine();
inp = inp.replace("<Год>", "yyyy");
inp = inp.replace("<Месяц>", "MM");
inp = inp.replace("<Число>", "dd");
inp = inp.replace("<Часы1>", "hh");
inp = inp.replace("<минуты>", "mm");
SimpleDateFormat f = new SimpleDateFormat(inp);
System.out.println("Текущая дата:\n" + f.format(Calendar.getInstance().getTime()));
}
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-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>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p13</artifactId>
<description>13</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package mirea.lab13;

import java.util.Locale;
import java.util.Scanner;

public abstract class Prac13p1 {
public static String p1(String s) {
return s;
}

public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Введите строку: ");
String s = sc.nextLine();
System.out.println("P1: " + p1(s));
System.out.println("P2: " + s.charAt(s.length() - 1));
System.out.println("P3: " + s.endsWith("!!!"));
System.out.println("P4: " + s.startsWith("I like"));
System.out.println("P5: " + s.contains("Java"));
System.out.println("P6: " + s.lastIndexOf("Java"));
System.out.println("P7: " + s.replace("a", "o"));
System.out.println("P8: " + s.toUpperCase(Locale.getDefault()));
System.out.println("P9: " + s.toLowerCase(Locale.getDefault()));
System.out.println("P10: " + s.substring(s.lastIndexOf("Java"), s.lastIndexOf("Java") + 4));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mirea.lab13;

public abstract class Prac13p5 {
public static String phoneFormat(String p) {
if (p.startsWith("8")) {
p = p.replaceFirst("8", "+7");
}
if (p.startsWith("+")) {
return p.substring(0, 2) + " " + p.substring(2, 5) + "-" + p.substring(5, 8) + "-" + p.substring(8);
} else {
return " ";
}
}

public static void main(String[] args) {
System.out.println(phoneFormat("+71346644453"));
System.out.println(phoneFormat("89653050013"));
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-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>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p14</artifactId>
<description>14</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mirea.lab14;

import java.util.Scanner;

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

public abstract class Prac14p2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
String ex = "abcdefghijklmnopqrstuv18340";
System.out.print("Введите строку: ");
String inp = sc.nextLine();
if (inp.matches(ex)) {
System.out.println("Строка совпадает с " + ex);
} else {
System.out.println("Строка не совпадает с " + ex);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package mirea.lab14;

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

/* Дан текст со списками цен. Извлечь из него цены в USD, RUВ, EU */

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

Pattern p = Pattern.compile("(\\d+\\.\\d\\d ((USD)|(RUB)|(EU)))");
System.out.print("Введите строку: ");
String inp = sc.nextLine();
Matcher m = p.matcher(inp);
if (m.find()) {
System.out.println(m.group(1));
}
}
}
}
13 changes: 13 additions & 0 deletions students/23K0563/23K0563-p17/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>23K0563</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0563-p17</artifactId>
<description>17</description>
</project>
59 changes: 59 additions & 0 deletions students/23K0563/23K0563-p17/src/main/java/mirea/lab17/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package mirea.lab17;


public class List<E> {
Node<E> node;

List() {
node = null;
}

public void add(E e) {
if (node == null) {
node = new Node<E>(e);
return;
}
Node<E> nNode = node;
Node<E> newNode = new Node<E>(e);

while (nNode.next != null) {
nNode = nNode.next;
}
newNode.pr = nNode;
nNode.next = newNode;
}

public void pr() {
if (node != null) {
Node<E> dNode = node;

while (dNode != null) {
System.out.println(dNode.getData());
dNode = dNode.next;
}
}
}

public boolean isEmpty() {
return node == null;
}

public void clr() {
node = null;
}

public void remove() {
Node<E> dNode = node;
while (dNode.next != null) {
dNode = dNode.next;
}
dNode.pr.next = null;
}

public String current() {
if (node.cur != null) {
return node.cur.toString();
}
return "";
}
}
24 changes: 24 additions & 0 deletions students/23K0563/23K0563-p17/src/main/java/mirea/lab17/Node.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mirea.lab17;

public class Node<E> {
Node<E> pr;
E cur;
Node<E> next;

Node(E cur, Node<E> next, Node<E> pr) {
this.pr = pr;
this.cur = cur;
this.next = next;
}

Node(E e) {
cur = e;
next = null;
pr = null;
}

public String getData() {
return cur.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mirea.lab17;

import java.util.Scanner;

public abstract class Prac17p1 {
public static void main(String[] args) {
List<Student> students = new List<Student>();
try (Scanner sc = new Scanner(System.in)) {
int scount = 5;
for (int i = 0; i < scount; i++) {
System.out.println("Студент № " + (i + 1));
students.add(new Student(sc.nextLine(), sc.nextLine(), sc.nextLine()));
}
System.out.println();
students.pr();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mirea.lab17;

public abstract class Prac17p2 {
public static void main(String[] args) {
List<Student> students = new List<Student>();
students.add(new Student("Egor Sidorov", "RTU Mirea", "KABO-01-23"));
students.add(new Student("Not Egor Sidorov", "Not RTU Mirea", "1111"));
students.add(new Student("Hihihi huhuhu", "School 3", "9B"));
students.pr();
System.out.println(students.isEmpty());
students.remove();
students.pr();
students.clr();
System.out.println(students.isEmpty());
}
}
Loading
Loading